【发布时间】:2015-02-16 20:33:04
【问题描述】:
如何将此代码部分从 XAML 转换为 C# 代码?
<ComboBoxItem x:Name="cmbItemDashDot1">
<Viewbox>
<Image Height="18" Width="70">
<Image.Source>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="Black">
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,9" EndPoint="38,9" />
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Brush="Black" Thickness="1" DashStyle="{x:Static DashStyles.DashDot}"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Viewbox>
</ComboBoxItem>
我找不到某些元素的类比。 或者如何以编程方式在 ComboBoxItem 中画一条线?
【问题讨论】:
-
检查您的项目是否引用了
System.Windows.Media -
找不到类比 - 那是什么?你想念命名空间吗?
ComboBoxItem是System.Windows.Controls.ComboBoxItem(或者只是添加using System.Windows.Controls;)。如果问题是这样,那么您可以使用 google 查找哪个命名空间是控制(键入“wpf controlname”)。或者只需右键单击代码中的ComboBoxItem文本并选择Resolve,智能感知将为您修复它。