Wpf 呈现自定义附着的属性值
我需要在XAML中执行此操作:Wpf 呈现自定义附着的属性值,wpf,rendering,attached-properties,Wpf,Rendering,Attached Properties,我需要在XAML中执行此操作: <Grid x:Name="layoutRoot"> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <SomeUserControl Grid.Row="0" />
<Grid x:Name="layoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<SomeUserControl Grid.Row="0" />
<ui:AdditionalView.UseCase1>
<ContentControl>
<TextBlock>aaa</TextBlock>
</ContentControl>
</ui:AdditionalView.UseCase1>
</Grid>
你想达到什么目标?这在你的帖子里是不清楚的!是-请解释您的目标我必须实现的想法是使用一个很酷的xaml名称创建不同的区域,这些区域可以根据它们的。。。类型对于用例1,我将使该块可见,对于用例2,我将使另一块可见。。等等当然,我可以在stackpanel中设置一些内容控件,并通过其visibility属性上的绑定来切换它们的可见性,但我被分配了这个。。
<TextBlock>aaa</TextBlock>
<ContentControl Grid.Row="1" Content="{Binding ElementName=layoutRoot, Path=(ui:AdditionalView.UseCase1)}" />
public class AdditionalView
{
public static readonly DependencyProperty UseCase1Property = DependencyProperty.RegisterAttached(
"UseCase1",
typeof(object),
typeof(AdditionalView),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)
);
public static void SetUseCase1(UIElement element, Boolean value)
{
element.SetValue(UseCase1Property, value);
}
public static object GetUseCase1(UIElement element)
{
return element.GetValue(UseCase1Property);
}
}