更新的值未反映在WPF的UI中
我正在尝试在ListView中填充和导航面板DynamicCali更新的值未反映在WPF的UI中,wpf,data-binding,prism,software-design,Wpf,Data Binding,Prism,Software Design,我正在尝试在ListView中填充和导航面板DynamicCali <ListView Background="Transparent" HorizontalAlignment="Center" x:Name="viewItemControl" ItemsSource="{Binding Views}"> <ListView.ItemsPanel> <ItemsPanelTemplate>
<ListView Background="Transparent" HorizontalAlignment="Center" x:Name="viewItemControl" ItemsSource="{Binding Views}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<Button Style="{StaticResource PluginViewButton}"
Command="{Binding ElementName=viewItemControl,Path=DataContext.NavigateCommand}"
CommandParameter="{Binding ViewName}"
BorderThickness="{Binding Path = ViewObj.DataContext.IsSelected, Converter={StaticResource BoolToThicknessConverter},Mode=OneWay}">
<Button.Content>
<Grid Background="White">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="15"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding Icon, Mode=OneTime}"></Image>
<TextBlock Grid.Row="1" Text="{Binding DisplayableName}" HorizontalAlignment="Center"/>
</Grid>
</Button.Content>
</Button>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Focusable" Value="false"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
接口IPluggableView由我的所有用户控件实现,这些控件都是视图
我的viewmodel基类有一个属性IsSelected。
Viewmodel类正在实现VigationAware接口中的prism功能,因此在OnNavigatedTo和OnNavigatedFrom函数中,我正在更新IsSelected属性
我希望我的按钮边框在其视图被选中时更厚,当我导航到另一个视图时,它应该返回默认值,如下所示
所以我编写了BoolToThickness转换器,它根据值返回0.5或2
我面临的问题是,它在加载时只更新一次,然后再也不会更新,尽管我更新了IsSelected属性
我有点确定UI没有得到RaisePropertyChanged事件。但我知道如何解决这个问题。
如果这是一个设计问题,请帮助我纠正。您应该定义
ItemContainerStyle
并直接在IsSelected
上触发。只有在要修改或删除默认高亮显示行为时,才需要覆盖控制模板
:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="BorderBrush"
Value="Black" />
<!-- Optional -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Change border thickness on item is selected -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderThickness" Value="3" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="BorderBrush"
Value="Black" />
<!-- Optional -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- Change border thickness on item is selected -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderThickness" Value="3" />
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<Button BorderThickness="{Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=ListViewItem}, Path=IsSelected, Converter={StaticResource BoolToThicknessConverter}}">