小编Max*_*Max的帖子

android错误:无法从parcel读取输入通道文件描述符

我已经为Android创建了一个或多或少类似的应用程序:

  • 应用程序与Web服务通信并传输信息(而不是文件)
  • 我可以使用Intent和导航到不同的屏幕startActivity

不幸的是,有时应用程序在不同的活动中崩溃并出现以下错误:

java.lang.RuntimeException: Could not read input channel file descriptors from parcel.  
at android.view.InputChannel.nativeReadFromParcel(Native Method)  
at android.view.InputChannel.readFromParcel(InputChannel.java:135)  
at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:523)  
at android.view.ViewRootImpl.setView(ViewRootImpl.java:481)  
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301)  
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)  
at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)  
at android.view.Window$LocalWindowManager.addView(Window.java:537)  
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2507)  
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)  
at android.app.ActivityThread.access$600(ActivityThread.java:123)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)  
at android.os.Handler.dispatchMessage(Handler.java:99)  
at android.os.Looper.loop(Looper.java:137)  
at android.app.ActivityThread.main(ActivityThread.java:4424)  
at java.lang.reflect.Method.invokeNative(Native Method)  
at java.lang.reflect.Method.invoke(Method.java:511)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)  
at dalvik.system.NativeStart.main(Native Method) 
Run Code Online (Sandbox Code Playgroud)

但我不知道这个错误是什么意思,因为我不使用文件.任何的想法?

java android

7
推荐指数
1
解决办法
1万
查看次数

如何正确提高ItemsControl加载并避免冻结

我想知道改善 ItemsControl 加载的正确方法是什么。我想要显示加载量相当大的项目(由于复杂的 XAML),并且我不希望我的 WPF 应用程序冻结。我希望我的项目在渲染后显示出来,并且能够同时与窗口的其他元素进行交互(即使速度有点慢)。首先是一些假设:

  1. 假设我无法缩短物品的加载时间;
  2. 我无法使用虚拟化,因为我需要立即查看所有项目;
  3. 视图不等待后台操作完成,所有工作都在 UI 线程上完成。

我已经找到了解决方法,但我对此不满意,使用 aBackgroundWorker和 a sleep:

在此输入图像描述

主窗口.xaml

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:local="clr-namespace:WpfApplication1">
    <DockPanel>
        <Button DockPanel.Dock="Bottom" Content="Click me" Click="OnButtonClick"/>

        <ItemsControl ItemsSource="{Binding Items}">
            <!-- Items begin to be loaded once the ItemsControl is loaded -->
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Loaded">
                    <i:InvokeCommandAction Command="{Binding LoadCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Width="25" Height="25" Background="Red" Margin="5">
                        <local:HeavyItem Content="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </Border>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </DockPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

ViewModel.cs

public class ViewModel …
Run Code Online (Sandbox Code Playgroud)

c# wpf animation xaml itemscontrol

5
推荐指数
1
解决办法
1751
查看次数

WPF验证错误

在我目前的项目中,我必须以WPF形式处理数据验证.我的表单位于ResourceDictionnary中的DataTemplate中.我可以通过两个按钮来保存和加载表单中的数据,这两个按钮序列化和反序列化数据(通过两个DelegateCommand).

如果我的表单中的一个字段为空或无效,则禁用保存按钮.由于UpdateSourceTrigger属性,每次更改时都会检查一个字段.这就是为什么我需要在C#代码中知道如果字段无效以更新我的保存命令.

目前,我在我的XAML绑定中使用ExceptionValidationRule,我想知道它是否是一个很好的实践.我无法实现ValidationRule,因为我需要在C#代码中知道字段是否无效,以更新保存命令(启用或禁用保存按钮).

<TextBox>
    <Binding Path="Contact.FirstName" UpdateSourceTrigger="PropertyChanged">
        <Binding.ValidationRules>
            <ExceptionValidationRule/>
        </Binding.ValidationRules>
    </Binding>
</TextBox>
Run Code Online (Sandbox Code Playgroud)

在这篇博客中,我们可以阅读:

在Setter中引发异常并不是一个很好的方法,因为这些属性也是由代码设置的,有时可以暂时保留它们的错误值.

我已经阅读过这篇文章,但我不能使用它,我的TextBox在DataTemplate中,我不能在我的C#代码中使用它们.

所以,我想知道我是否应该更改我的数据验证并且不要使用ExceptionValidationRule.

data-binding validation wpf validationrule

4
推荐指数
1
解决办法
5112
查看次数

如何在TabControl模板中获取所选项的标题?

我试图让头部的的选择的项目在我的模板TabControl的,但我不能这样做.我尝试了几种解决方案但没有一种方法可行:

没有结果 :

<ContentPresenter ContentSource="{TemplateBinding SelectedItem}"/>
Run Code Online (Sandbox Code Playgroud)

编译错误(因为SelectedItem的类型是对象,而不是HeaderedContentControl):

<ContentPresenter ContentSource="{TemplateBinding SelectedItem.Header}"/>
Run Code Online (Sandbox Code Playgroud)

在C#中很容易得到它,但我想把它放在我的TabControl模板中.

有人有什么想法吗?

谢谢

wpf xaml tabcontrol header tabitem

2
推荐指数
1
解决办法
2069
查看次数