带数据模板的 Wpf ItemsControl,某些项目的双边框问题
我有带有自定义数据模板的简单 ItemsControl,模板仅包含带边框的文本块。所有项目都应该一个接一个地垂直显示,但有些项目有额外的边框。 我怎样才能删除它?
我想实现类似于 enso launcher 的东西,它看起来像
我的实现如下
这是我的 xaml 代码:
<Window x:Class="winmole.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
x:Name="hostWindow"
Height="Auto"
MinHeight="100"
MinWidth="100"
Width="Auto"
Padding="10"
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Top="0"
Left="0"
SizeToContent="WidthAndHeight"
Topmost="True"
Loaded="Window_Loaded"
KeyUp="Window_KeyUp"
>
<Window.Resources>
<!--Simple data template for Items-->
<DataTemplate x:Key="itemsTemplate">
<Border Background="Black" Opacity="0.9" HorizontalAlignment="Left" CornerRadius="0,2,2,0">
<TextBlock Text="{Binding Path=Title}"
TextWrapping="Wrap"
FontFamily="Georgia" FontSize="30"
Height="Auto"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
TextAlignment="Left" Padding="5" Margin="0" Foreground="Yellow"/>
</Border>
</DataTemplate>
</Window.Resources>
<DockPanel>
<ItemsControl DockPanel.Dock="Bottom" Name="itcPrompt"
ItemsSource="{Binding ElementName=hostWindow, Path=DataItems}"
ItemTemplate="{StaticResource itemsTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
I have simple ItemsControl with custom datatemplate, template contains only textblock with border. All items should be displayed vertically one after another, but some items have extra border.
How can I remove it?
I want to achieve something similar to enso launcher, it looks like
My implementation looks like this
here is my xaml code:
<Window x:Class="winmole.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
x:Name="hostWindow"
Height="Auto"
MinHeight="100"
MinWidth="100"
Width="Auto"
Padding="10"
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Top="0"
Left="0"
SizeToContent="WidthAndHeight"
Topmost="True"
Loaded="Window_Loaded"
KeyUp="Window_KeyUp"
>
<Window.Resources>
<!--Simple data template for Items-->
<DataTemplate x:Key="itemsTemplate">
<Border Background="Black" Opacity="0.9" HorizontalAlignment="Left" CornerRadius="0,2,2,0">
<TextBlock Text="{Binding Path=Title}"
TextWrapping="Wrap"
FontFamily="Georgia" FontSize="30"
Height="Auto"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
TextAlignment="Left" Padding="5" Margin="0" Foreground="Yellow"/>
</Border>
</DataTemplate>
</Window.Resources>
<DockPanel>
<ItemsControl DockPanel.Dock="Bottom" Name="itcPrompt"
ItemsSource="{Binding ElementName=hostWindow, Path=DataItems}"
ItemTemplate="{StaticResource itemsTemplate}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DockPanel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题:尝试在边框上设置
SnapsToDevicePixels="True"
If I understand your question correctly: Try to set
SnapsToDevicePixels="True"
on the Border