Click here to Skip to main content
16,016,795 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Conditional DataBinding to UI Elements Pin
Mycroft Holmes5-Feb-12 13:15
professionalMycroft Holmes5-Feb-12 13:15 
GeneralRe: Conditional DataBinding to UI Elements Pin
SledgeHammer015-Feb-12 14:14
SledgeHammer015-Feb-12 14:14 
GeneralRe: Conditional DataBinding to UI Elements Pin
Mycroft Holmes5-Feb-12 15:15
professionalMycroft Holmes5-Feb-12 15:15 
AnswerRe: Conditional DataBinding to UI Elements Pin
Mycroft Holmes5-Feb-12 15:16
professionalMycroft Holmes5-Feb-12 15:16 
GeneralRe: Conditional DataBinding to UI Elements Pin
Andy_L_J5-Feb-12 15:43
Andy_L_J5-Feb-12 15:43 
QuestionOwn TreeViewItem with image and text Pin
Mc_Topaz2-Feb-12 22:20
Mc_Topaz2-Feb-12 22:20 
AnswerRe: Own TreeViewItem with image and text Pin
Mc_Topaz3-Feb-12 0:52
Mc_Topaz3-Feb-12 0:52 
GeneralGridSplitter Conundrum Pin
Gil Yoder1-Feb-12 15:31
Gil Yoder1-Feb-12 15:31 
I have been trying to understand how the GridSplitter works in WPF, so I have written a few tests using it in various environments. In that process I have noticed some odd behavior. Since my tests are using only binding and are written only with XAML I wonder if what I see is evidence of buggy code within WPF, or if I am doing something that should not be done.

I have a WPF application that opens a Window defined using this xaml, and only the default code behind:

<Window x:Class="GridSplitter.GridSplitterWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="GridSplitter"
        Width="580"
        Height="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Name="c0"
                              Width="*" />
            <ColumnDefinition Name="c1"
                              Width="*" />
            <ColumnDefinition Name="c2"
                              Width="*" />
            <ColumnDefinition Name="c3"
                              Width="*" />
            <ColumnDefinition Name="c4"
                              Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <TextBlock Name="col0"
                   Grid.Row="0"
                   Grid.Column="0"
                   Text="Col 0 Actual Width"
                   TextWrapping="Wrap" />
        <TextBlock Grid.Row="1"
                   Grid.Column="0"
                   Text="{Binding ElementName=col0,
                                  Path=ActualWidth,
                                  StringFormat=\{0:F\}}" />
        <TextBlock Name="col1"
                   Grid.Row="0"
                   Grid.Column="1"
                   Text="Col 1 Actual Width"
                   TextWrapping="Wrap" />
        <TextBlock Grid.Row="1"
                   Grid.Column="1"
                   Text="{Binding ElementName=col1,
                                  Path=ActualWidth,
                                  StringFormat=\{0:F\}}" />
        <TextBlock Name="col2"
                   Grid.Row="0"
                   Grid.Column="2"
                   Text="Col 2 Actual Width"
                   TextWrapping="Wrap" />
        <TextBlock Grid.Row="1"
                   Grid.Column="2"
                   Text="{Binding ElementName=col2,
                                  Path=ActualWidth,
                                  StringFormat=\{0:F\}}" />
        <TextBlock Name="col3"
                   Grid.Row="0"
                   Grid.Column="3"
                   Text="Col 3 Actual Width"
                   TextWrapping="Wrap" />
        <TextBlock Grid.Row="1"
                   Grid.Column="3"
                   Text="{Binding ElementName=col3,
                                  Path=ActualWidth,
                                  StringFormat=\{0:F\}}" />
        <TextBlock Name="col4"
                   Grid.Row="0"
                   Grid.Column="4"
                   Text="Col 4 Actual Width"
                   TextWrapping="Wrap" />
        <TextBlock Grid.Row="1"
                   Grid.Column="4"
                   Text="{Binding ElementName=col4,
                                  Path=ActualWidth,
                                  StringFormat=\{0:F\}}" />
        <TextBlock Grid.Row="2"
                   Grid.Column="0"
                   Text="Width"
                   TextWrapping="Wrap" />
        <TextBox Grid.Row="3"
                 Grid.Column="0"
                 Text="{Binding Path=Width,
                                ElementName=c0,
                                Mode=TwoWay}" />
        <TextBlock Grid.Row="2"
                   Grid.Column="1"
                   Text="Width"
                   TextWrapping="Wrap" />
        <TextBox Grid.Row="3"
                 Grid.Column="1"
                 Text="{Binding Path=Width,
                                ElementName=c1,
                                Mode=TwoWay}" />
        <TextBlock Grid.Row="2"
                   Grid.Column="2"
                   Text="Width"
                   TextWrapping="Wrap" />
        <TextBox Grid.Row="3"
                 Grid.Column="2"
                 Text="{Binding Path=Width,
                                ElementName=c2,
                                Mode=TwoWay}" />
        <TextBlock Grid.Row="2"
                   Grid.Column="3"
                   Text="Width"
                   TextWrapping="Wrap" />
        <TextBox Grid.Row="3"
                 Grid.Column="3"
                 Text="{Binding Path=Width,
                                ElementName=c3,
                                Mode=TwoWay}" />
        <TextBlock Grid.Row="2"
                   Grid.Column="4"
                   Text="Width"
                   TextWrapping="Wrap" />
        <TextBox Grid.Row="3"
                 Grid.Column="4"
                 Text="{Binding Path=Width,
                                ElementName=c4,
                                Mode=TwoWay}" />
        <GridSplitter Grid.RowSpan="4"
                      Grid.Column="2"
                      Width="4"
                      VerticalAlignment="Stretch" />
    </Grid>
</Window>


The Binding does two things: (1) It tells me what is the ActualWidth of the columns. (I am actually binding to Labels that have their Width property set to "Auto". When I tried to bind to the ActualWidth of the ColumnDefinition tags, I started seeing some of the behavior I'll describe below, so I thought I'd try this as a workaround.) (2) It allows me to change the Width property of the columns during run time.

When I compile and execute and use the GridSpliter, several things occur that I think should not. To cut to the chase I'll enumerate:

1. If you run the window just as I have written it, and then move the GridSplitter to the left, the third column collapses unexpectedly hiding most of its contents. (Strike this. I've just discovered why this happens, but I'll wait before I explain. It might be a nice puzzle to figure out.)

2. If all of the columns are given a Width of Auto, it is possible to push the two left columns beyond the right edge of the Window, and even beyond so that the GridSplitter could not be grabbed by the mouse, if it was dropped there.

3. If the two outer columns on both sides are given a Width of 100, and the middle column is given a Width of "*", it is possible to move the GridSplitter to the left of the middle column and this results in pushing the two columns on the right to the right, again right off the Window!

Item #1 I know is because of the Binding and the design of the window, so I would not consider it evidence of a bug in Microsoft's code. But what of #2 and #3? Is that a result of something I wrote in XAML, or is it due to poor validation in the Grid and GridSplitter code?

When I saw this I thought of CodePlex, and wondered if users here would be intrigued with this strange behavior. So, what do you think?
QuestionRe: GridSplitter Conundrum Pin
Gil Yoder2-Feb-12 9:44
Gil Yoder2-Feb-12 9:44 
AnswerRe: GridSplitter Conundrum Pin
SledgeHammer012-Feb-12 11:40
SledgeHammer012-Feb-12 11:40 
GeneralRe: GridSplitter Conundrum Pin
Gil Yoder2-Feb-12 14:09
Gil Yoder2-Feb-12 14:09 
GeneralRe: GridSplitter Conundrum Pin
SledgeHammer012-Feb-12 14:37
SledgeHammer012-Feb-12 14:37 
GeneralRe: GridSplitter Conundrum Pin
Gil Yoder2-Feb-12 15:43
Gil Yoder2-Feb-12 15:43 
SuggestionRe: GridSplitter Conundrum Pin
Gil Yoder2-Feb-12 18:59
Gil Yoder2-Feb-12 18:59 
GeneralRe: GridSplitter Conundrum Pin
SledgeHammer013-Feb-12 7:17
SledgeHammer013-Feb-12 7:17 
Questionadding/removing ListView columns at runtime (revisited) Pin
Vincent Beek1-Feb-12 0:20
Vincent Beek1-Feb-12 0:20 
AnswerRe: adding/removing ListView columns at runtime (revisited) Pin
Abhinav S1-Feb-12 0:36
Abhinav S1-Feb-12 0:36 
GeneralRe: adding/removing ListView columns at runtime (revisited) Pin
Mycroft Holmes1-Feb-12 11:53
professionalMycroft Holmes1-Feb-12 11:53 
QuestionBinding list of items to IntemsControl in WPF Pin
rams230-Jan-12 23:14
rams230-Jan-12 23:14 
AnswerRe: Binding list of items to IntemsControl in WPF Pin
Wayne Gaylard31-Jan-12 0:10
professionalWayne Gaylard31-Jan-12 0:10 
GeneralRe: Binding list of items to IntemsControl in WPF Pin
rams231-Jan-12 0:36
rams231-Jan-12 0:36 
GeneralRe: Binding list of items to IntemsControl in WPF Pin
Wayne Gaylard31-Jan-12 0:39
professionalWayne Gaylard31-Jan-12 0:39 
GeneralRe: Binding list of items to IntemsControl in WPF Pin
Abhinav S1-Feb-12 16:26
Abhinav S1-Feb-12 16:26 
GeneralRe: Binding list of items to IntemsControl in WPF Pin
Wayne Gaylard1-Feb-12 19:06
professionalWayne Gaylard1-Feb-12 19:06 
QuestionFocusing on elements in MVVM Pin
mi_n30-Jan-12 22:42
mi_n30-Jan-12 22:42 

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.