Click here to Skip to main content
15,886,919 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Canvas with an Image Pin
Christian Graus19-Jun-09 11:02
protectorChristian Graus19-Jun-09 11:02 
GeneralMessage Removed Pin
19-Jun-09 11:13
professionalN_tro_P19-Jun-09 11:13 
GeneralRe: Canvas with an Image Pin
Christian Graus19-Jun-09 11:25
protectorChristian Graus19-Jun-09 11:25 
GeneralMessage Removed Pin
19-Jun-09 11:28
professionalN_tro_P19-Jun-09 11:28 
GeneralRe: Canvas with an Image Pin
Christian Graus19-Jun-09 11:37
protectorChristian Graus19-Jun-09 11:37 
GeneralRe: Canvas with an Image Pin
Mark Salsbery21-Jun-09 7:33
Mark Salsbery21-Jun-09 7:33 
QuestionHow to remember the position of a GridSplitter Pin
fjparisIII19-Jun-09 8:57
fjparisIII19-Jun-09 8:57 
AnswerRe: How to remember the position of a GridSplitter (I "SOLVED" IT MYSELF) Pin
fjparisIII19-Jun-09 11:37
fjparisIII19-Jun-09 11:37 
I searched the Code Project for the answer to this question and couldn't find one. I also Googled for it and found several proposed and confusing answers that I couldn't make much sense of. People don't seem to be very clear about what they really want. So I thought I'd ask the question on this Code Project WPF forum, but in the meantime I kept working on an answer myself. After trying a bunch of possibilities for a couple hours, I got the idea of remembering the width of the ColumnDefinition rather than the width of the element contained in the column. By itself, the latter doesn't work, but it does in conjunection with the former, depending on what you actually want to do. After receiving some success using the column definition, I ran into other problems, stemming from the fuzzy idea I had about the actual behavior I wanted. Eventually I defined that as follows, which may not be what you want:

Before my change, the position of my GridSplitter was automatically set to 1/3 the width of the grid and changing the width of the containing window maintained this 1/3 proportional ratio. I decided that for my application, this was undesirable behavior. I wanted the width of the left panel to remain fixed as the width of the window changed, and I wanted only the width of the right panel to change as I manually changed the width of the window. This required defining my grid columns as follows:

<Grid.ColumnDefinitions>
    <ColumnDefinition Name="treeColumn" Width="0"/>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition  Width="*"/>
</Grid.ColumnDefinitions>

The middle column corresponds to the GridSplitter. The width of the left column is set to 0 in this markup because that is actually the property I want to set programmatically in code-behind, both when the window is loaded and when the user drags the GridSplitter.

The only thing I had to work out is that the Width property of a ColumnDefinition is a GridLength object, not a simple double.

The other thing I had to figure out is what event to look for. I already explained in my initial post that SizeChanged on the element in the left column didn't work, and neither did MouseLeftButtonUp. I wasn't getting either event. That's because these are bubbling events that are being handled by higher level controls. I needed a tunneling event, a Preview event. For my purposes, PreviewMouseLeftButtonUp on the GridSplitter did the trick. Here is that event from my code-behind:

private void mainSplitter_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
    State.TreeWidth = treeColumn.Width.Value;
    treeCtrl.Width = frameForPages.Width - 16;
}

(The hard-coded 16 is a kludge: the hard-coded width of the left and right border. I'll clean this up later.) Now all I needed was the code to set the initial width of left column (treeControl) when my application started:

treeColumn.Width = new GridLength(State.TreeWidth);
treeCtrl.Width = frameForPages.Width - 16;

So now I know how to save the position of the GridSplitter from one invocation of its window to the next, and the next time someone searches for the answer to this question, hopefully he'll run into this post and see what some of the issues are that need to be addressed to accomplish the behavior he wants.

modified on Friday, October 30, 2009 12:12 PM

GeneralRe: How to remember the position of a GridSplitter (I SOLVED IT MYSELF) Pin
Christian Graus19-Jun-09 12:46
protectorChristian Graus19-Jun-09 12:46 
GeneralRe: How to remember the position of a GridSplitter (I "SOLVED" IT MYSELF) Pin
fjparisIII19-Jun-09 13:55
fjparisIII19-Jun-09 13:55 
GeneralRe: How to remember the position of a GridSplitter (I SOLVED IT MYSELF) Pin
Christian Graus19-Jun-09 17:37
protectorChristian Graus19-Jun-09 17:37 
Questionxmlns question Pin
#realJSOP19-Jun-09 4:39
mve#realJSOP19-Jun-09 4:39 
AnswerRe: xmlns question [modified] Pin
Eslam Afifi19-Jun-09 6:29
Eslam Afifi19-Jun-09 6:29 
AnswerRe: xmlns question Pin
Christian Graus19-Jun-09 11:45
protectorChristian Graus19-Jun-09 11:45 
GeneralRe: xmlns question Pin
#realJSOP19-Jun-09 15:15
mve#realJSOP19-Jun-09 15:15 
GeneralRe: xmlns question Pin
Mark Salsbery21-Jun-09 7:47
Mark Salsbery21-Jun-09 7:47 
AnswerRe: xmlns question Pin
SteveTheThread22-Jun-09 0:18
SteveTheThread22-Jun-09 0:18 
QuestionWeb browser application having database Pin
Rits11038918-Jun-09 21:34
Rits11038918-Jun-09 21:34 
AnswerRe: Web browser application having database Pin
Christian Graus18-Jun-09 23:54
protectorChristian Graus18-Jun-09 23:54 
GeneralRe: Web browser application having database Pin
#realJSOP19-Jun-09 0:11
mve#realJSOP19-Jun-09 0:11 
GeneralRe: Web browser application having database Pin
Rits11038919-Jun-09 0:27
Rits11038919-Jun-09 0:27 
GeneralRe: Web browser application having database Pin
Christian Graus19-Jun-09 11:00
protectorChristian Graus19-Jun-09 11:00 
GeneralRe: Web browser application having database Pin
Rits11038919-Jun-09 0:24
Rits11038919-Jun-09 0:24 
GeneralRe: Web browser application having database Pin
Christian Graus19-Jun-09 10:59
protectorChristian Graus19-Jun-09 10:59 
GeneralRe: Web browser application having database Pin
Rits11038920-Jun-09 1:27
Rits11038920-Jun-09 1:27 

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.