このような機能が実現されます
バックグラウンド結合からのデータにカスタムスタイルスタイル列ヘッダー
これは言っヘッドスタイルとスタイルデータバインディングヘッド
思考
1)関数は、最初に達成したいことは、列ヘッダーのスタイルを使用することを選択した編集にあるだろうというときDataGridTextColumnの編集DataGridColumnHeaderのスタイルを
スタイルは、この良い終わりをレイアウトすることは非常に簡単です
2)動的な列は、我々は完全にここにいたループデータに直接戻ってMVVMの書き込みを使用していないので、再舗装する必要はありません。
-
List<
string> LS =
new List<
string>();
-
-
public void addColumn()
-
{
-
LS.Add(
"表下カップ綿天竺仮縫い_37s_C_1");
-
LS.Add(
"上カップマーキしつけ_28s_C_2");
-
LS.Add(
"上下カップ接ぎ_33s_C_3");
-
LS.Add(
"上下カップ押え_62s_B_4");
-
LS.Add(
"カップ脇しつけ_14s_B_5");
-
LS.Add(
"表上カップレース端押さえ_41s_B_6");
-
-
for (
int i =
0; i < LS.Count; i++)
-
{
-
DataGridTextColumn dl =
new DataGridTextColumn();
-
dl.Header=LS[i];
-
-
dataGrid.Columns.Add(dl);
-
}
-
-
}
3)過酷なデータ・バインドされたデータソースのヘッダーのみ2ヶ月がある場合は、その上にパターンTemplateBindingの結合コンテンツやタグから直接のControlTemplateを持つので、多くの問題を持っていないでしょう
{TemplateBindingのコンテンツ}
タグ内のコンテンツ=ヘッダ値がコース追加タグの値パターンのマストを使用することについて上記で{TemplateBindingのタグ}結合します
しかし、私はより多くの、これは私はテンプレートが、少し情報を拡張したいを確認バインディングTemplateBindingの自慢に必要な4つの項目を必要とします
回避策独善与えられた制御
それ退屈なビットは愚かな解決策になるけれども、私はlable書き込み依存関係プロパティをカスタマイズしたように、最初に私がlableコントロールを表示します
1)データ及びヘッダデータ処理を得るために、MSを定義
Contentプロパティのlableにバインド定義MYPROPERTYのMS治療を得るために、データ2)
タグ3)そのlableを区別するためのコントロール自体の使用
コードを貼り付けます。
カスタムコントロールlable
-
public
class
LableColumn :
Label
-
{
-
public LableColumn()
-
: base()
-
{
-
}
-
-
//获得值
-
public
string Ms
-
{
-
get {
return (
string)GetValue(MsProperty); }
-
set { SetValue(MsProperty,
value); }
-
}
-
-
// Using a DependencyProperty as the backing store for ms. This enables animation, styling, binding, etc...
-
public
static
readonly DependencyProperty MsProperty =
-
DependencyProperty.Register(
"Ms",
typeof(
string),
typeof(LableColumn),
new FrameworkPropertyMetadata(
"", Onshow));
-
-
-
-
//用于绑定的值
-
public
string MyProperty
-
{
-
get {
return (
string)GetValue(MyPropertyProperty); }
-
set { SetValue(MyPropertyProperty,
value); }
-
}
-
-
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
-
public
static
readonly DependencyProperty MyPropertyProperty =
-
DependencyProperty.Register(
"MyProperty",
typeof(
string),
typeof(LableColumn),
new PropertyMetadata(
""));
-
-
-
-
-
-
private static void Onshow(DependencyObject d, DependencyPropertyChangedEventArgs e)
-
{
-
LableColumn l = d
as LableColumn;
-
-
if (l.Ms !=
null && l.Ms !=
"")
-
{
-
String[] strarr = l.Ms.ToString().Split(
new
string[] {
"_" }, StringSplitOptions.None);
-
-
if (l.Tag.Equals(
"1"))
-
{
-
l.MyProperty= strarr[
3];
-
}
-
else
if (l.Tag.Equals(
"2"))
-
{
-
l.MyProperty = strarr[
0];
-
-
}
-
else
if (l.Tag.Equals(
"3"))
-
{ l.MyProperty= strarr[
2] ;
-
}
-
else
if (l.Tag.Equals(
"4"))
-
{
-
l.MyProperty= strarr[
1];
-
}
-
}
-
}
-
-
-
}
フロントデスクDataGridColumnHeaderのスタイル
-
<Style TargetType=
"{x:Type DataGridColumnHeader}">
-
<Setter Property=
"VerticalContentAlignment" Value=
"Center"/>
-
<Setter Property=
"Template">
-
<Setter.Value>
-
<ControlTemplate TargetType=
"{x:Type DataGridColumnHeader}">
-
-
<Grid HorizontalAlignment=
"Left " Height=
"Auto " VerticalAlignment=
"Stretch " Width=
"Auto " Background=
"White " Margin=
"0 ">
-
<Grid.RowDefinitions>
-
<RowDefinition Height=
"* "/>
-
</Grid.RowDefinitions>
-
<Border BorderBrush=
"Black " BorderThickness=
"1 " HorizontalAlignment=
"Stretch " Height=
"Auto " Margin=
"0 " VerticalAlignment=
"Stretch " Grid.RowSpan=
"1 ">
-
<Grid HorizontalAlignment=
"Stretch " Height=
"Auto " Margin=
"-1,0,0,0 " VerticalAlignment=
"Stretch ">
-
<Grid.RowDefinitions>
-
<RowDefinition Height=
"20* "/>
-
<RowDefinition Height=
"20* "/>
-
<RowDefinition Height=
"20* "/>
-
<RowDefinition Height=
"20* "/>
-
</Grid.RowDefinitions>
-
<Border BorderBrush=
"Black " BorderThickness=
"1,1,0,1 " HorizontalAlignment=
"Stretch " Height=
"Auto " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"Auto " Grid.Row=
"1 ">
-
<local:LableColumn Tag=
"3" Content=
"{Binding RelativeSource={RelativeSource self},Path=MyProperty}" Ms=
"{TemplateBinding Content}" Background=
"#FFF9F9F9 " HorizontalAlignment=
"Stretch " Height=
"25 " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"82 "/>
-
</Border>
-
<Border BorderBrush=
"Black " BorderThickness=
"1,1,0,1 " HorizontalAlignment=
"Stretch " Height=
"Auto " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"Auto ">
-
<local:LableColumn Tag=
"1" Content=
"{Binding MyProperty, RelativeSource={RelativeSource self}}" Ms=
"{TemplateBinding Content}" Background=
"#FFF9F9F9 " HorizontalAlignment=
"Stretch " Height=
"25 " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"82 "/>
-
</Border>
-
<local:LableColumn x:Name=
"lText" Tag=
"2" Content=
"{Binding MyProperty, RelativeSource={RelativeSource self}}" Ms=
"{TemplateBinding Content}" Background=
"#FFF9F9F9 " HorizontalAlignment=
"Stretch " Height=
"35 " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"82 " Visibility=
"Collapsed"/>
-
-
<Border BorderBrush=
"Black " BorderThickness=
"1,1,0,1 " HorizontalAlignment=
"Stretch " Height=
"Auto " Margin=
"0,0,0,0 " VerticalAlignment=
"Stretch " Width=
"Auto " Grid.Row=
"2 ">
-
<TextBlock TextWrapping =
"Wrap " Background=
"#FFF9F9F9 " Text=
"{Binding Path=Content,ElementName=lText}" HorizontalAlignment=
"Stretch " Height=
"35 " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"82 "/>
-
-
</Border>
-
<Border BorderBrush=
"Black " BorderThickness=
"1,1,0,1 " HorizontalAlignment=
"Stretch " Height=
"Auto " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"Auto " Grid.Row=
"3 ">
-
<local:LableColumn Tag=
"4" Content=
"{Binding MyProperty, RelativeSource={RelativeSource self}}" Ms=
"{TemplateBinding Content}" Background=
"#FFF9F9F9 " HorizontalAlignment=
"Stretch " Height=
"35 " Margin=
"0 " VerticalAlignment=
"Stretch " Width=
"82 "/>
-
</Border>
-
</Grid>
-
</Border>
-
</Grid>
-
-
</ControlTemplate>
-
</Setter.Value>
-
</Setter>
-
</Style>
データバインディングは、ここではスキルの2種類を含み、
結合特性そのものであります
{Binding MyProperty, RelativeSource={RelativeSource self}}
第二は、他のコントロールの結合特性であります
{Binding Path=Content,ElementName=lText}
この希望は、共有学習へのメッセージだった達成するためのより良い方法があるに違いありません