我已经创建了一个程序来存储我的类型Project的任意数量的对象.然后每个项目包含任意数量的文件,这是我为该程序创建的另一个对象.
我遇到的问题出现在XAML中,有两个方面,但我认为它有类似的起源.
我有一个窗口,其中包含一个ListView,填充了所选项目中的文件.从这里我可以选中每个旁边的框以打开或关闭它们,如果我选择一个文件,它的相关信息将显示在此窗口的状态栏中.
如果我关闭文件,它的文本颜色应该在ListView中显示为浅灰色,但它不会自动执行此操作; 我必须关闭窗口并重新打开它.File实现了INotifyPropertyChanged,并在开/关状态发生变化时触发此事件.
我使用这个XAML代码,转换器在我的代码后面的类:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Foreground" Value="{Binding Path=IsVisible, Converter={StaticResource VisibleStateToFontColourConverter}}"/>
</Style>
</ListBox.ItemContainerStyle>
Run Code Online (Sandbox Code Playgroud)
同样对于选定的文件,如果文件中的信息在选择时发生变化(其他类可能导致发生),我希望状态栏自动更新以反映此更改,但它不会; 我必须点击其他内容,然后重新选择感兴趣的文件.我也为此实现并使用了INotifyPropertyChanged,因此我不知道为什么它不会自动更新.我的状态项的XAML代码如下:
<StatusBarItem Name="statusItem_FileInfo" Content="{Binding ElementName=loadedFiles_ListView, Path=SelectedItem, Converter={StaticResource GIS_FileToInfoConverter}}"/>
Run Code Online (Sandbox Code Playgroud)
有谁知道我错过了什么会把它们全部结合在一起?
尝试添加UpdateSourceTrigger=PropertyChanged到您的绑定:
Value = "{Binding ... , UpdateSourceTrigger=PropertyChanged}"
Run Code Online (Sandbox Code Playgroud)
使用已OnPropertyChanged更改属性的名称更改属性后直接调用:
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler == null) return;
handler (this, new PropertyChangedEventArgs(propertyName));
}
Run Code Online (Sandbox Code Playgroud)
如果你换了"IsVisible"电话OnPropertyChanged("IsVisible")
| 归档时间: |
|
| 查看次数: |
10286 次 |
| 最近记录: |