Click here to Skip to main content
15,887,986 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Binding in a WPF TreeViewItem Pin
#realJSOP7-Nov-12 5:24
mve#realJSOP7-Nov-12 5:24 
GeneralRe: Binding in a WPF TreeViewItem Pin
#realJSOP8-Nov-12 4:30
mve#realJSOP8-Nov-12 4:30 
GeneralRe: Binding in a WPF TreeViewItem Pin
#realJSOP8-Nov-12 5:53
mve#realJSOP8-Nov-12 5:53 
GeneralRe: Binding in a WPF TreeViewItem Pin
#realJSOP8-Nov-12 10:13
mve#realJSOP8-Nov-12 10:13 
Questionslide menu Pin
HimmelDeveloper2-Nov-12 6:51
HimmelDeveloper2-Nov-12 6:51 
AnswerRe: slide menu Pin
Richard MacCutchan2-Nov-12 10:27
mveRichard MacCutchan2-Nov-12 10:27 
QuestionCustomized Scrollbar not working properly Pin
Anil_S.Kamble2-Nov-12 5:11
Anil_S.Kamble2-Nov-12 5:11 
QuestionCustom TreeViewItems Pin
#realJSOP2-Nov-12 4:06
mve#realJSOP2-Nov-12 4:06 
I need to add two TextBlocks to each TreeView item, and have them be right-justified in the tree (in other words, butted up against the right side of the tree.

I've tried the following (this is the TreeView xaml), and I get the desired TextBlocks, but the are right next to the TreeViewItem itself.

XML
<TreeView Name="sceneTree" 
          ItemContainerStyle="{DynamicResource SceneTreeItemStyle}" 
          PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown">
    <TreeView.Resources>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="HeaderTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Border Grid.Column="0" BorderThickness="2,0,0,0" BorderBrush="Transparent" 
                                    Background="Transparent" x:Name="PART_ItemBorder" Margin="0" 
                                    Padding="1,0,0,0" HorizontalAlignment="Stretch">
                                <Label Content="{Binding}" />
                            </Border>
                            <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                                <TextBlock Text=" ? " FontFamily="Arial" FontWeight="ExtraBlack" Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
                                <TextBlock Text=" X " FontFamily="Arial" FontWeight="ExtraBlack" Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </TreeView.Resources>
</TreeView>


The SceneTreeItemStyle looks like this (and the two TextBlock objects are displaying where I want them):

XML
<Style x:Key="SceneTreeItemStyle" TargetType="{x:Type TreeViewItem}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="HorizontalContentAlignment" 
            Value="{Binding HorizontalContentAlignment, 
            RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="VerticalContentAlignment" 
            Value="{Binding VerticalContentAlignment, 
            RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
    <Setter Property="Padding" Value="1,0,0,0"/>
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
    <Setter Property="FontWeight" Value="Normal" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TreeViewItem}">
                <Grid >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition MinWidth="19" Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <ToggleButton x:Name="Expander" ClickMode="Press" 
                                      IsChecked="{Binding IsExpanded, 
                                      RelativeSource={RelativeSource TemplatedParent}}" 
                                      Style="{StaticResource ExpandCollapseToggleStyle}"/>
                    <Border x:Name="Bd"
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Background="{TemplateBinding Background}" 
                                Grid.Column="1" Padding="{TemplateBinding Padding}" 
                                SnapsToDevicePixels="true">
                        <ContentPresenter x:Name="PART_Header" ContentSource="Header" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                    <ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="3" Grid.Column="1" 
                                    Grid.Row="1" HorizontalAlignment="Stretch"  />
                    <StackPanel Orientation="Horizontal" Grid.Column="3" HorizontalAlignment="Right">
                        <TextBlock Text=" ? " FontFamily="Arial" FontWeight="ExtraBlack" 
                                   Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
                        <TextBlock Text=" X " FontFamily="Arial" FontWeight="ExtraBlack" 
                                   Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
                    </StackPanel>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>    


Can anyone help?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997


AnswerRe: Custom TreeViewItems Pin
SledgeHammer012-Nov-12 6:47
SledgeHammer012-Nov-12 6:47 
QuestionHow to detect if the users pressed Ctrl and V at the same time? Pin
gmf1-Nov-12 11:26
gmf1-Nov-12 11:26 
AnswerRe: How to detect if the users pressed Ctrl and V at the same time? Pin
Pete O'Hanlon1-Nov-12 11:49
mvePete O'Hanlon1-Nov-12 11:49 
GeneralRe: How to detect if the users pressed Ctrl and V at the same time? Pin
gmf1-Nov-12 13:28
gmf1-Nov-12 13:28 
GeneralRe: How to detect if the users pressed Ctrl and V at the same time? Pin
Pete O'Hanlon1-Nov-12 13:34
mvePete O'Hanlon1-Nov-12 13:34 
QuestionXAML Diff Source Compare Pin
_Maxxx_30-Oct-12 15:04
professional_Maxxx_30-Oct-12 15:04 
AnswerRe: XAML Diff Source Compare Pin
Mycroft Holmes30-Oct-12 17:42
professionalMycroft Holmes30-Oct-12 17:42 
GeneralRe: XAML Diff Source Compare Pin
_Maxxx_30-Oct-12 23:19
professional_Maxxx_30-Oct-12 23:19 
AnswerRe: XAML Diff Source Compare Pin
Abhinav S30-Oct-12 21:22
Abhinav S30-Oct-12 21:22 
GeneralRe: XAML Diff Source Compare Pin
_Maxxx_30-Oct-12 23:20
professional_Maxxx_30-Oct-12 23:20 
AnswerRe: XAML Diff Source Compare Pin
Pete O'Hanlon30-Oct-12 22:32
mvePete O'Hanlon30-Oct-12 22:32 
GeneralRe: XAML Diff Source Compare Pin
_Maxxx_30-Oct-12 23:24
professional_Maxxx_30-Oct-12 23:24 
QuestionHow to set the wcf ria service time out. Pin
Saurabh_0829-Oct-12 11:32
Saurabh_0829-Oct-12 11:32 
AnswerRe: How to set the wcf ria service time out. Pin
Keith Barrow29-Oct-12 23:18
professionalKeith Barrow29-Oct-12 23:18 
QuestionDownload Xap file in silverlight4.0 Pin
Saurabh_0829-Oct-12 11:28
Saurabh_0829-Oct-12 11:28 
AnswerRe: Download Xap file in silverlight4.0 Pin
Mycroft Holmes29-Oct-12 12:56
professionalMycroft Holmes29-Oct-12 12:56 
AnswerRe: Download Xap file in silverlight4.0 Pin
Abhinav S30-Oct-12 6:40
Abhinav S30-Oct-12 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.