110,545
社区成员
发帖
与我相关
我的任务
分享
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace MyWpfTest.control
{
public class DesignerLayerNameTextBox : Control
{
public DesignerLayerNameTextBox()
{
// 这里如何写成DesignerLayerStenclis.xaml中的定义呢?
// 我这里不建议使用:XamlWrite或是XamlReader,的读写字符串方式;
// 我只想用纯过程式代码;比较容易把控;
// 因为我有好几个地方的ItemsControl的Items.Add()或是Item.Remove()的控件都有对应的模板;
// 而,很多情况,Remove之后,再Add回去,发现,好多内容,自动还原成ControlTemplate定义的内容;
// 原因不明,如果能写成过程式,估计,能比较容易发现问题;
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:baseControl="clr-namespace:MyWpfTest.control"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!--图层名称的文本框-->
<Style TargetType="{x:Type baseControl:DesignerLayerNameTextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type baseControl:DesignerLayerNameTextBox}">
<Grid>
<TextBox x:Name="TextBox" Text="图层1"
HorizontalAlignment="Stretch" VerticalContentAlignment="Center"
BorderThickness="0" Background="Transparent" IsHitTestVisible="False"
Focusable="False"/>
<Rectangle
x:Name="HotAreaRect"
Fill="Transparent"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Focusable ="False"
/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>