Wpf ItemsControl with datatemplate, problem with doubled border for some items

Posted by ksirg on Stack Overflow See other posts from Stack Overflow or by ksirg
Published on 2011-01-04T15:06:12Z Indexed on 2011/01/04 21:54 UTC
Read the original article Hit count: 197

Hi,

I have simple ItemsControl with custom datatemplate, template contains only textblock with border. All items should be displayed vericaly 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 alt text

My implementation looks like this

wpf textblock with border

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>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datatemplate