I have created a WPF UserCotrol. Inside of it I have 3 Grids that are by default
visibility="collapsed"
. I have created a dependency property like this:
public int PanelId
{
get { return (int)GetValue(PanelIdProperty); }
set { SetValue(PanelIdProperty, value); }
}
public static readonly DependencyProperty PanelIdProperty =
DependencyProperty.Register("PanelId", typeof(int), typeof(RecurrencePattern), new UIPropertyMetadata(1));
我想在另一个Xaml中利用这一用户控制。 我宣布:
<uc:RecurrencePattern PanelId="2"/>
I thought that by doing this the PanelId would be 2 and in the default constructor when run I could use it to set what panel will be visible. Instead the PanelId is 1 as defined by UIPropertyMetadata(1). How can I use the value provided in xaml to set the which grid to be visible. I have:
<Grid x:Name="a" Visibility="Collapsed">
<label Content"a"/>
</Grid>
<Grid x:Name="b" Visibility="Collapsed">
<label Content"b"/>
</Grid>
<Grid x:Name="c" Visibility="Collapsed">
<label Content"c"/>
</Grid>
在违约情况下,被告是:
switch (PanelId)
{
case 1:
a.Visibility = System.Windows.Visibility.Visible;
break;
case 2:
b.Visibility = System.Windows.Visibility.Visible;
break;
case 3:
c.Visibility = System.Windows.Visibility.Visible;
break;
default:
a.Visibility = System.Windows.Visibility.Visible;
break;
}
谢谢。