我想在Xamarin.Forms中为我的页面使用自定义ContentPage.我尝试创建一个自定义类并在xaml中指定页面,如下所示:
<local:ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamarinFormsApp.Controls"
x:Class="XamarinFormsApp.Views.WelcomeView">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</local:ContentPage>
Run Code Online (Sandbox Code Playgroud)
这将(通常)在xaml中工作,但在Xamarin.Forms中给出了这个错误:
Error 7 The "XamlG" task failed unexpectedly.
System.Exception: Can't load types from xmlns clr-namespace:XamarinFormsApp.Controls
at Xamarin.Forms.Build.Tasks.XamlG.GetNamespace(String namespaceuri)
at Xamarin.Forms.Build.Tasks.XamlG.GetType(String nsuri, String type, IList`1 typeArguments, Func`2 getNamespaceOfPrefix)
at Xamarin.Forms.Build.Tasks.XamlG.GenerateFile(String xamlFile, String outFile)
at Xamarin.Forms.Build.Tasks.XamlG.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() XamarinFormsApp.iOS
Run Code Online (Sandbox Code Playgroud)
这个(还)是不受支持的还是我做错了什么?
我正在尝试在调试器从进程中分离时运行一些代码.很容易找出是否附加了调试器:
System.Diagnostics.Debugger.IsAttached;
Run Code Online (Sandbox Code Playgroud)
我的问题是,当调试器被分离时(大多数是在应用程序被杀死时),有一种方法(最好是适用于.NET,Windows Phone,WinRT的方法)来获取事件.
最糟糕的情况我可以在.NET中找到调试器进程并订阅Exit事件,但这在Windows Phone和WinRT中不起作用.
我很怀疑。我有一个大列表容器,可能有数千个项目。当我虚拟化(这几乎是对性能的需求)时,一旦我尝试更新选择,我就会收到此异常:
Failed to update selection | [Exception] System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at System.Runtime.InteropServices.WindowsRuntime.IVector`1.RemoveAt(UInt32 index)
at System.Runtime.InteropServices.WindowsRuntime.VectorToListAdapter.RemoveAtHelper[T](IVector`1 _this, UInt32 index)
at System.Runtime.InteropServices.WindowsRuntime.VectorToListAdapter.RemoveAt[T](Int32 index)
at MyApp.Views.SearchView.<>c__DisplayClass9_0.<UpdateListViewSelection>b__0()
at MyApp.Views.SearchView.<>c__DisplayClass10_0.<<ExecuteSafely>b__0>d.MoveNext()
Run Code Online (Sandbox Code Playgroud)
我尝试通过两种方式清除选择:
A:
listView.SelectedItems.Clear();
Run Code Online (Sandbox Code Playgroud)
乙:
for (int i = 0; i < listView.SelectedItems.Count; i++)
{
listView.SelectedItems.RemoveAt(i--);
}
Run Code Online (Sandbox Code Playgroud)
另一种选择是不虚拟化,但更糟糕的是......任何人都知道如何安全地清除 UWP 中虚拟化列表视图上的选择?