1
比方說,我有這樣的用戶控件:UserControl可以用來格式化內容嗎?
<UserControl x:Class="BorderWithHeader"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel Orientation="Vertical">
<Border BorderThickness="1" BorderBrush="Gray" Height="50">
<TextBlock Text="{Binding Header, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" />
</Border>
<Border BorderThickness="1" BorderBrush="Gray" Height="500">
<!--I want to display complex content here (i.e. containers, grids, stackpanels, etc.)-->
</Border>
</StackPanel>
</UserControl>
用下面的代碼背後:
public partial class BorderWithHeader : UserControl
{
public string Header
{
get { return (string)GetValue(HeaderProperty); }
set { SetValue(HeaderProperty, value); }
}
public BorderWithHeader()
{
InitializeComponent();
}
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(BorderWithHeader), new FrameworkPropertyMetadata(OnHeaderPropertyChanged));
private static void OnHeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
}
}
我想在我的觀點一個用這樣的:
<viewsCommon:BorderWithHeader Header="Title">
<!--I want to define complex content here (i.e. containers, grids, stackpanels, etc.)-->
</viewsCommon:BorderWithHeader>
的頭文件綁定很好用,但我無法將自己的想法包裝在如何使內容綁定起作用。這是甚至可能的,還是我以錯誤的方式接近這一點?如果是這樣,那麼應該怎麼做呢?
http://stackoverflow.com/questions/4630218 /指定 - 這屬性-去-之間最開閉標籤的在-XAML – 2014-09-18 17:37:29