[英]Path and XAML controls
為了在工具箱上顯示對象並允許用戶將其拖放到畫布上,我使用以下控件:
<HeaderedItemsControl x:Key="itemABC"
Width="100"
Height="100"
Canvas.Left="210"
Canvas.Top="220"
Margin="0,0,0,0"
Style="{StaticResource ABC_Style}">
</HeaderedItemsControl>
和
在風格上有定義:
<Style x:Key="ABC_Style" TargetType="HeaderedItemsControl">
<Setter Property="Data" Value="M10.395,0.5 L30.237,0.5 30.237,5.0359993 39.499999,5.0359993 39.499999,22.75 30.237,22.75 30.237,42.660999 39.499999,42.660999 39.499999,60.375 30.237,60.375 30.237,65 10.395,65 10.395,58.124999 0.5,58.124999 0.5,10 10.395,10 z"/>
</Style>
但是,問題是HeaderdItemsControl沒有Path屬性(據我所知),所以我想知道我在這里還能有什么其他選擇。
實際上,我需要在XAML中顯示HeaderedItemsControl內部的路徑。
謝謝。
此示例有效:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="HeaderedItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type HeaderedItemsControl}">
<StackPanel>
<Grid>
<Rectangle Fill="{TemplateBinding Background}"/>
<ContentPresenter ContentSource="Header"/>
</Grid>
<Grid>
<Rectangle Stroke="{TemplateBinding BorderBrush}"/>
<ItemsPresenter Margin="2,0,0,0"/>
</Grid>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<PathGeometry x:Key="ABC_Style">
M10.395,0.5 L30.237,0.5 30.237,5.0359993 39.499999,5.0359993 39.499999,22.75 30.237,22.75 30.237,42.660999 39.499999,42.660999 39.499999,60.375 30.237,60.375 30.237,65 10.395,65 10.395,58.124999 0.5,58.124999 0.5,10 10.395,10 z
</PathGeometry>
</Window.Resources>
<Grid>
<HeaderedItemsControl>
<HeaderedItemsControl.Header>
<Path Stroke="Black" Data="{StaticResource ABC_Style}" />
</HeaderedItemsControl.Header>
</HeaderedItemsControl>
</Grid>
</Window>
由於我以外的原因, HeaderedItemsControl
的默認樣式通常實際上並不包含標題。 同樣,您嘗試將標頭設置為您擁有的路徑數據的方法也不正確,因此我通過將PathGeometry
定義為靜態資源,然后包含使用該Header
作為Header
的Path
來修復了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.