我想創建一個自定義的DependencyProperty的用戶控件自定義的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));
這裏表是用來存儲行&欄自定義數據類型。這會幫助我像使用它們;
<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中使用網格=「10」時,它會中斷。 任何人都可以幫助我實現這一目標嗎?
然後你承擔責任:水災做到以下幾點:
my:MyViewer> –
XamlZealot
謝謝!我可以用這種方式達到結果。然而,@Clemens解決方案更具有吸引力和簡單性。 <我:MyViewer 的HorizontalAlignment = 「左」 保證金= 「66,54,0,0」 X:NAME = 「MyViewer1」 VerticalAlignment = 「評出的」 HEIGHT = 「400」 WIDTH = 「400」 網格= 「10,20」/> – Riju