ユーザー コントロールのカスタム DependencyProperty を作成したい
public Table Grids
{
get { return (Table)GetValue(GridsProperty); }
set { SetValue(GridsProperty, value); }
}
// Using a DependencyProperty as the backing store for Grids. This enables animation, styling, binding, etc...
public static readonly DependencyProperty GridsProperty =
DependencyProperty.Register("Grids", typeof(Table),
typeof(MyViewer), new UIPropertyMetadata(10));
ここで Table は、行と列を格納するために使用されるカスタム データ型です。それは私がそれらを次のように使用するのに役立ちます;
<my:MyViewer
HorizontalAlignment="Left"
Margin="66,54,0,0"
x:Name="MyViewer1"
VerticalAlignment="Top"
Height="400"
Width="400"
Grids="10"/>
また
<my:MyViewer
HorizontalAlignment="Left"
Margin="66,54,0,0"
x:Name="MyViewer1"
VerticalAlignment="Top"
Height="400"
Width="400"
Grids="10,20"/>
テーブルのデータ型を次のように定義しようとしました。
public class Table
{
public int Rows { get; set; }
public int Columns { get; set; }
public Table(int uniform)
{
Rows = uniform;
Columns = uniform;
}
public Table(int rows, int columns)
{
Rows = rows;
Columns = columns;
}
}
しかし、それは機能していません。XAML で Grids="10" を使用すると壊れます。誰でもこれを達成するのを手伝ってもらえますか?