2
我想創建一個自定義的控制,這樣我可以做這樣的事情:WPF自定義控件的並排佈局
<SideBySide>
<StackPanel SideBySide.Left="True">...</StackPanel>
<StackPanel SideBySide.Right="False">...</StackPanel>
</SideBySide>
我將使用這遍的地方,顯然更選項(大小等)。
我已經考慮過使用Panel子類,但這看起來不正確(在左邊和右邊有一個選定項的概念)。
所以,我想使用ItemsControl的子類 - 現在,有沒有人知道如何把項目放在控制模板的ItemsControl?
這是SideBySide縮寫的模板:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary1">
<Style TargetType="{x:Type local:SideBySideControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SideBySideControl}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Rectangle}">
<Setter Property="Margin"
Value="5" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0"
VerticalAlignment="Stretch">
<!-- PART_LeftContent goes here -->
</Grid>
<GridSplitter Width="3"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
ShowsPreview="False">
</GridSplitter>
<Grid Grid.Column="2">
<!-- PART_RightContent goes here -->
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
+1這正是我所知尋找。你有完整的樣本的任何鏈接? – bendewey 2009-09-01 00:39:14