Click here to Skip to main content
15,890,376 members
Home / Discussions / WPF
   

WPF

 
QuestionSilverlight ---- Viewbox Control : How ? Pin
milestanley1-Jun-10 21:26
milestanley1-Jun-10 21:26 
AnswerRe: Silverlight ---- Viewbox Control : How ? Pin
Abhinav S1-Jun-10 21:47
Abhinav S1-Jun-10 21:47 
GeneralRe: Silverlight ---- Viewbox Control : How ? Pin
milestanley1-Jun-10 22:07
milestanley1-Jun-10 22:07 
AnswerRe: Silverlight ---- Viewbox Control : How ? Pin
Abhinav S1-Jun-10 23:11
Abhinav S1-Jun-10 23:11 
GeneralRe: Silverlight ---- Viewbox Control : How ? Pin
milestanley1-Jun-10 23:34
milestanley1-Jun-10 23:34 
AnswerRe: Silverlight ---- Viewbox Control : How ? Pin
Peace ON1-Jun-10 22:17
Peace ON1-Jun-10 22:17 
AnswerRe: Silverlight ---- Viewbox Control : How ? Pin
Mamta D3-Jul-10 20:51
Mamta D3-Jul-10 20:51 
QuestionHow do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
fjparisIII1-Jun-10 8:20
fjparisIII1-Jun-10 8:20 
I'm using the Silverlight 4 Tookit Expander all over the place. They are all contained within a ScrollViewer. Sometimes when I expand one of the Expander elements, the Expander.Header winds up above the top of the ScrollViewer and hence is not visible and so you can't see the title of the content that has been expanded. What I would like to do is center the Expander header vertically within the ScrollViewer viewport when I expand the Expander. To do this I have to set the ScrollViewer.VerticalOffset to the right value that will center the Expander in the ScrollViewer viewport.

So I think I understand the problem that needs to be solved. But I haven't found a solution. Hopefully it's simple and I'm just overlooking something.

The only ScrollViewer properties I've found that might be relevant to this problem are the following: ViewportHeight, VerticalOffset, ExtentHeight, and ActualHeight. I also have the mouse cursor Point relative to the Expander when the Expanded event takes place. But even with all this information, I don't seem to have the right information to compute what the VerticalOffset of the ScrollViewer should be.

SOLUTION: Chalk up my inability to solve this to plain and simple User Brain Damage. The solution was SMOP: a Small Matter Of Programming.

Most of the properties I identified above are not needed, only the following: VerticalOffset, ViewportHeight, and the Y coordinate of the mouse cursor position. Oh, yes! You have to perform the computation in the right event: Expander.SizeChanged, not Expander.Expanded. Only perform the offset if Expander.IsExpanded is true.

So the code in my SizeChanged event looks like this:
private void expander_SizeChanged(object sender, SizeChangedEventArgs e)
{
    Expander expander = sender as Expander;
    if (expander != null && expander.IsExpanded)
    {
        double viewportHeight = scrollViewer.ViewportHeight;
        double verticalOffset = scrollViewer.VerticalOffset;
        double mouseVerticalOffset = MouseCursorPosition.Y;
        double newVerticalOffset = 
            verticalOffset - viewportHeight / 2 + mouseVerticalOffset;
        scrollViewer.ScrollToVerticalOffset(newVerticalOffset);
    }
}

FYI, MouseCursorPosition is one of my properties, set in my ScrollViewer's MouseMove event. Seems kind of expensive, but it doesn't seem to interfere with the UI response and I don't know of any other way to get the mouse cursor position.
AnswerRe: How do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
fjparisIII1-Jun-10 10:22
fjparisIII1-Jun-10 10:22 
GeneralStoryboard Animation of ScrollBar is not possible Pin
fjparisIII1-Jun-10 12:31
fjparisIII1-Jun-10 12:31 
AnswerRe: How do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
Abhinav S1-Jun-10 17:36
Abhinav S1-Jun-10 17:36 
GeneralRe: How do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
fjparisIII1-Jun-10 18:27
fjparisIII1-Jun-10 18:27 
GeneralRe: How do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
Abhinav S1-Jun-10 23:22
Abhinav S1-Jun-10 23:22 
GeneralRe: How do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
fjparisIII2-Jun-10 4:32
fjparisIII2-Jun-10 4:32 
GeneralRe: How do you vertically center an Expander within a ScrollViewer when it expands? [SOLVED] Pin
fjparisIII2-Jun-10 11:04
fjparisIII2-Jun-10 11:04 
QuestionMore complex databinding Pin
Lutosław1-Jun-10 2:40
Lutosław1-Jun-10 2:40 
AnswerRe: More complex databinding Pin
Abhinav S1-Jun-10 3:16
Abhinav S1-Jun-10 3:16 
QuestionRe: More complex databinding Pin
Lutosław1-Jun-10 5:00
Lutosław1-Jun-10 5:00 
AnswerRe: More complex databinding Pin
AspDotNetDev2-Jun-10 12:56
protectorAspDotNetDev2-Jun-10 12:56 
QuestionAs www.k12.com in this site i need About us menu pop as it is in using silverlight control Pin
Ch.Gayatri Subudhi30-May-10 20:12
Ch.Gayatri Subudhi30-May-10 20:12 
AnswerRe: As www.k12.com in this site i need About us menu pop as it is in using silverlight control Pin
Abhinav S30-May-10 20:23
Abhinav S30-May-10 20:23 
GeneralRe: As www.k12.com in this site i need About us menu pop as it is in using silverlight control Pin
Ch.Gayatri Subudhi30-May-10 20:34
Ch.Gayatri Subudhi30-May-10 20:34 
QuestionValidation in silverlight datagrid? Pin
mittalpa30-May-10 6:11
mittalpa30-May-10 6:11 
QuestionWPF and Threading Pin
cdpace30-May-10 2:44
cdpace30-May-10 2:44 
AnswerRe: WPF and Threading Pin
Abhishek Sur1-Jun-10 0:48
professionalAbhishek Sur1-Jun-10 0:48 

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.