<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Resources><DataTemplate x:Key="mDataTemplate">
<Button BorderBrush="#FF767171" Margin="10,10,0,0" Click="button1_Click" IsEnabled="{Binding Enabled}">
<Button.Content>
<Grid x:Name="ButtonGrid" Height="Auto" HorizontalAlignment="Left" erticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Height="Auto" HorizontalAlignment="Left" Text="{Binding TitleText}" VerticalAlignment="Top" Width="Auto" FontSize="30" />
<TextBlock Grid.Row="1" Height="Auto" HorizontalAlignment="Left" Text="{Binding DetailText}" VerticalAlignment="Top" Margin="10,0,0,0" Width="Auto" FontSize="20" />
</Grid> </Button.Content> </Button> </DataTemplate> </Grid.Resources>
我的代码。
public class AboutData
{
public string TitleText { get; set; }
public string DetailText { get; set; }
public bool Enabled { get; set; }
}
}
列表框的加载事件
ObservableCollection<AboutData> aCollection = new ObservableCollection<AboutData>();
aCollection.Add(new AboutData { TitleText="Title1", DetailText="Detail1", Enabled= true});
aCollection.Add(new AboutData { TitleText="Title2", DetailText="Detail2", Enabled= true});
aCollection.Add(new AboutData { TitleText="Title3", DetailText="Detail3", Enabled= true});
ContentPanel.DataContext = aCollection;
加载 listBox1 (我的列表框)时,我创建了 AboutData 的 ObservableCollection 并将其分配给 ControlPanel.DataContext
我想在单击某个按钮时禁用我的 lisbox 中的按钮。不知道怎么样。帮助赞赏。