AutoGenerateColumns
を使用すると、AutoGeneratingColumn
イベントをコードバックで処理し、新しく作成したConnected
DataGridCheckBoxColumnを変更することができます。私はするつもりです何を、ChechBoxに依存ステータステキストを変更しますトリガーにチェックを作成することです状態:
private void DataGridAutoGeneratingColumnHandler(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyName == "Connected")
{
var c = e.Column as DataGridCheckBoxColumn;
if (c == null)
return;
c.IsReadOnly = true;
c.ElementStyle =
new Style
{
TargetType = typeof (CheckBox),
Setters =
{
new Setter { Property = ContentProperty, Value = "Disconnected" },
// prevent checking CheckBoxes
new Setter { Property = IsHitTestVisibleProperty, Value = false },
},
Triggers =
{
new Trigger
{
Property = CheckBox.IsCheckedProperty,
Value = true,
Setters =
{
new Setter { Property = ContentProperty, Value = "Connected" }
}
}
}
};
}
}
別のアイデア:接続用のViewModelに特別なプロパティを作りますステータスの説明。
public class Server
{
public string Name { get; set; }
public bool Connected { get; set; }
public string ConnectionStatus
{
get { return Connected ? "Connected" : "Disconnected"; }
}
}
して、これを反映する私のポストを編集、Connected
財産
private void DataGrid_AutoGeneratingColumnHandler(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
if (e.PropertyName == "Connected")
e.Cancel = true;
}
出典
2016-06-14 18:09:35
ASh
データグリッドコントロールの列の生成を無効にします。混乱の謝罪 –
は絶対に必要な ''自動生成列 'ですか?おそらくxamlに2列を定義する方が簡単です – ASh