Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
Wpf 更改ListBox.SelectionChanged上的属性在XAML中_Wpf_Xaml_Listbox - Fatal编程技术网

Wpf 更改ListBox.SelectionChanged上的属性在XAML中

Wpf 更改ListBox.SelectionChanged上的属性在XAML中,wpf,xaml,listbox,Wpf,Xaml,Listbox,我想编写XAML代码,在用户更改ListBox的selectionIndex时更改按钮的颜色。我怎么做?我试着 <Trigger Property="IsSelectionChanged" Value="True"> <Setter TargetName="btnSave" Property="Background" Value="Red" /> </Trigger> 但是未找到属性IsSelectionChanged。没有此类属性,您需要使用:

我想编写XAML代码,在用户更改ListBox的selectionIndex时更改按钮的颜色。我怎么做?我试着

<Trigger Property="IsSelectionChanged" Value="True">
    <Setter TargetName="btnSave" Property="Background" Value="Red" />
</Trigger>


但是未找到属性
IsSelectionChanged

没有此类属性,您需要使用:


没有此类属性,您需要使用:



{“RoutedEventConverter无法从System.String转换。”}您是否在样式上指定了
TargetType
(如果不指定,这正是您得到的错误;没有必要这样做,但如果不指定,则需要用类型
RoutedEvent=“ListBox.SelectionChanged”
限定事件){“RoutedEventConverter无法从System.String转换。”}您是否在样式上指定了
TargetType
(如果不指定它,这正是您得到的错误;没有必要这样做,但如果不指定,则需要使用类型
RoutedEvent=“ListBox.SelectionChanged”
限定事件)
<Button Name="buton" Content="The Buton"/>
<ListBox ItemsSource="{Binding Data}">
    <ListBox.Style>
        <Style TargetType="{x:Type ListBox}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="SelectionChanged">
                    <BeginStoryboard>
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.Target="{x:Reference buton}"
                                    Storyboard.TargetProperty="Background">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Brushes.Red}" />
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </ListBox.Style>
</ListBox>