Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有Observablecollection的Listview上的动画,对WPF中的项目进行排序时发生XamlParseException_C#_Wpf_Xaml - Fatal编程技术网

C# 具有Observablecollection的Listview上的动画,对WPF中的项目进行排序时发生XamlParseException

C# 具有Observablecollection的Listview上的动画,对WPF中的项目进行排序时发生XamlParseException,c#,wpf,xaml,C#,Wpf,Xaml,我遇到找不到属性背景的问题。当我在列表视图上使用动画时,不透明度 看看我的礼物。下图显示了我当前的工作状态 我收到一条错误消息,上面写着-找不到属性Backgorund.Opactiy。我觉得这很奇怪,因为在我分类之前它是有效的 首先查看我的xaml源代码 列表视图具有项目源。如果项目的属性选中为true,则它将开始情节提要,并将其背景设置为红色drawingbrush。我认为这个错误很奇怪的原因是,当我单击一个项目并使选中属性为true时,它工作正常。但是当我排序ObservableCo

我遇到
找不到属性背景的问题。当我在
列表视图上使用动画时,不透明度

看看我的礼物。下图显示了我当前的工作状态

我收到一条错误消息,上面写着-找不到属性
Backgorund.Opactiy
。我觉得这很奇怪,因为在我分类之前它是有效的

首先查看我的xaml源代码


列表视图具有项目源。如果项目的属性
选中
为true,则它将开始
情节提要
,并将其背景设置为红色
drawingbrush
。我认为这个错误很奇怪的原因是,当我单击一个项目并使
选中
属性为true时,它工作正常。但是当我排序
ObservableCollection
并分配
newobservableCollection
时,它会抛出一个错误

在xaml代码中,请参阅我的注释。在第二行,我试着不使用
Background
前缀<代码>情节提要。TargetProperty=“不透明”
然后它就可以工作了。请参见下图

您可以通知第一个图像和第二个图像之间的差异,但让我向您解释差异。第一个仅更改其背景笔刷不透明度,但第二个更改所有内容(包括文本)不透明度。我想实现第一个动画没有任何错误

谢谢你的阅读

我认为csharp代码没有问题,但我也会发布我的源代码。下面的源代码是我的csharp源代码

public分部类主窗口:窗口,INotifyPropertyChanged
{
布尔状态=假;
私人可观测收集资源;
公共事件属性更改事件处理程序属性更改;
public void onPropertyHagned([CallerMemberName]string name=null)=>PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(名称));
公共可观测收集资源
{
获取{return\u bSources;}
设置{u bSources=value;OnPropertyChagned();}
}
公共主窗口()
{
b来源=新的可观察收集
{新人(“김", "부산"), 新人(“정", "강원도新的人(“”)최", "서울新的人(“”)권", "전라도新的人(“”)박", "대전") };
初始化组件();
DataContext=this;
}
私有无效排序\单击(对象发送方,路由目标)
{
如果(州)
{
bsources=新的ObservableCollection(bsources.OrderBy(i=>i.Checked));
状态=假;
}
其他的
{
bsources=新的ObservableCollection(bsources.OrderByDescending(i=>i.Checked));
状态=真;
}
}
}
公共类人员:INotifyPropertyChanged
{
检查私人布尔;
公共图书馆检查
{
获取{return\u Checked;}
设置{u Checked=value;onPropertyHagned();}
}
私有字符串名称;
公共字符串名
{
获取{返回名称;}
设置{name=value;onPropertyHagned();}
}
私有字符串地址;
公共字符串地址
{
获取{return\u Address;}
设置{u Address=value;onPropertyHagned();}
}
公共事件属性更改事件处理程序属性更改;
public void onPropertyHagned([CallerMemberName]string name=null)=>PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(名称));
公众人物(字符串名称、字符串地址)
{
这个.Checked=false;
this.Name=Name;
这个地址=地址;
}
}
编辑 为更新
hasrerror
属性添加了按钮,该属性仅用于检查是否选中了
复选框。
下面是我的xaml代码,与原来的xaml源代码相比几乎没有变化。现在
DataTrigger
的绑定属性是
HasError
,DataTrigger.EnterAction被更改为
DataTrigger.ExitAction
。在堆栈面板下面我添加了新按钮进行更新
<Style TargetType="{x:Type StackPanel}">
    <Style.Setters>
        <Setter Property="Background">
            <Setter.Value>
                <DrawingBrush />
                <!--A default drawing brush-->
            </Setter.Value>
        </Setter>
    </Style.Setters>
    <Style.Triggers>
        <DataTrigger Binding="{Binding Checked}"
                     Value="True">
            <Setter Property="Background">
                <Setter.Value>
                    <DrawingBrush x:Name="errorBrush"
                                  TileMode="Tile"
                                  Viewport="0 0 1 1"
                                  ViewportUnits="Absolute">
                        <DrawingBrush.RelativeTransform>
                            <RotateTransform Angle="45" />
                        </DrawingBrush.RelativeTransform>
                        <DrawingBrush.Drawing>
                            <GeometryDrawing>
                                <GeometryDrawing.Geometry>
                                    <LineGeometry StartPoint="0,0"
                                                  EndPoint="4,2" />
                                </GeometryDrawing.Geometry>
                                <GeometryDrawing.Pen>
                                    <Pen Brush="Red"
                                         Thickness="4" />
                                </GeometryDrawing.Pen>
                            </GeometryDrawing>
                        </DrawingBrush.Drawing>
                    </DrawingBrush>
                </Setter.Value>
            </Setter>

            <DataTrigger.ExitActions>
                <BeginStoryboard>
                    <Storyboard>
                        <!-- Storyboard.TargetProperty = "opacity" throws no error -->
                        <DoubleAnimationUsingKeyFrames FillBehavior="Stop"
                                                       Storyboard.TargetProperty="Background.Opacity"
                                                       Duration="0:0:1">
                            <LinearDoubleKeyFrame KeyTime="0:0:0.0"
                                                  Value="0.2" />
                            <LinearDoubleKeyFrame KeyTime="0:0:0.3"
                                                  Value="0.3" />
                            <LinearDoubleKeyFrame KeyTime="0:0:0.5"
                                                  Value="0.8" />
                            <LinearDoubleKeyFrame KeyTime="0:0:1"
                                                  Value="1" />
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </DataTrigger.ExitActions>
        </DataTrigger>
    </Style.Triggers>
</Style>
<ListView ItemsSource="{Binding bsources}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <DataTemplate.Resources>
                <DrawingBrush x:Key="DB" Opacity="0" TileMode="Tile" Viewport="0 0 1 1" ViewportUnits="Absolute">
                    <DrawingBrush.RelativeTransform>
                        <RotateTransform Angle="45" />
                    </DrawingBrush.RelativeTransform>
                    <DrawingBrush.Drawing>
                        <GeometryDrawing>
                            <GeometryDrawing.Geometry>
                                <LineGeometry StartPoint="0,0" EndPoint="4,2" />
                            </GeometryDrawing.Geometry>
                            <GeometryDrawing.Pen>
                                <Pen Brush="Red" Thickness="4" />
                            </GeometryDrawing.Pen>
                        </GeometryDrawing>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </DataTemplate.Resources>
            <StackPanel Orientation="Horizontal">
                <StackPanel.Style>
                    <Style TargetType="{x:Type StackPanel}">
                        <Style.Setters>
                            <Setter Property="Background" Value="{StaticResource DB}"/>
                        </Style.Setters>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding HasError}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames
                                                FillBehavior="HoldEnd"
                                                Storyboard.TargetProperty="Background.Opacity"
                                                Duration="0:0:1">
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.0" Value="0.2" />
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.3" Value="0.3" />
                                                <LinearDoubleKeyFrame KeyTime="0:0:0.5" Value="0.8" />
                                                <LinearDoubleKeyFrame KeyTime="0:0:1" Value="1" />
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </DataTrigger.EnterActions>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding HasError}" Value="false">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <DrawingBrush Opacity="0" />
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </StackPanel.Style>
                <CheckBox IsChecked="{Binding Checked}" />
                <TextBlock Margin="20,0,0,0" Text="{Binding Name}" />
                <TextBlock Margin="20,0,0,0" Text="{Binding Address}" />
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>