我正在尝试将 bool 值绑定到 a 中的复选框GridViewColumn
,但它不起作用。我什至尝试只返回 false,但复选框看起来仍然启用。仅当我在 xaml 中键入“False”时它才有效。
绑定的属性是:
public bool HasPermissions
{
get { return this.UserPrivileges == UserPrivileges.FullAccess; }
}
的当前值this.UserPrivileges
不是UserPrivileges.FullAccess
。
Xml代码:
<Window x:Class="EffectsWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Effects Manager"
Width="800"
Height="500"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
<DockPanel VerticalAlignment="Stretch">
<DockPanel.Resources>
<ListView x:Name="EffectsListView"
ItemsSource="{Binding AllEffects}">
<ListView.View>
<GridView>
<GridViewColumn Width="50" Header="Override">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Margin="0"
HorizontalAlignment="Center"
IsEnabled="{Binding HasPermission}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</DockPanel>
</Window>
编辑:当前属性代码:
public bool HasPermissions
{
get { return this.UserPermissions == UserPermissions.FullAccess; }
set { this.RaisePropertyChanged ( "HasPermissions" ); }
}