This is a migrated thread and some comments may be shown as answers.

Setting IsExpanded from a UserControl

6 Answers 149 Views
Expander
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 11 Oct 2016, 03:19 AM

I am working on a Prism WPF project and I have a RadExpander in the shell of my project. 

 
    <Grid>
        <Grid>
            <ContentControl prism:RegionManager.RegionName="ContentRegion" />
            <tel:RadExpander x:Name="MenuFlyOut"
                             IsExpanded="True"
                             tel:AnimationManager.IsAnimationEnabled="True"
                             ExpandDirection="Right"
                             Width="210"
                             Background="CornflowerBlue"
                             Margin="0,0,159,0">
                <tel:RadExpander.Header>
                    <TextBlock x:Name="ExpanderCaption" Text="Menu" Foreground="White"/>
                </tel:RadExpander.Header>
                <tel:RadExpander.Content>
                    <StackPanel Margin="10,20,0,0" 
                                Width="200"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Top"
                                Opacity="1">
                        //Button that opens UserControl in ContentRegion
                        //stuff in the stackpanel
                    </StackPanel>
                </tel:RadExpander.Content>
            </tel:RadExpander>
        </Grid>
    </Grid>

Currently since the RadExpander IsExpanded is set to "true" when the UserControl loads, the RadExpander is, obviously, still expanded. What I am trying to do is change the state of IsExpanded when the UserControl finishes loading. 

 

my latest attempt was to set it in the codebehind of the UserControl: 

public partial class UserControlContent : UserControl
{
    public UserControlContent()
    {
        InitializeComponent();
 
        var setExpander = new Shell();
        setExpander.MenuFlyOut.IsExpanded = false;
 
    }
}

But that didn't work.. I've tried a few other ways to do this.  Event Triggers, Binding to a property which calls a method that sets IsExpanded.

 

Obviously, I'm missing something, and help would be appreciated.

6 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 11 Oct 2016, 07:11 AM
Hello Timothy,

I tested your code but I wasn't able to reproduce the described behavior. You can double check if the UserControl which you are using in code-behind is the same one as the one displayed in the view. You can also share runnable code snippets demonstrating the described behavior so that I can check them on my side and see if I can think of something.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Tim
Top achievements
Rank 1
answered on 12 Oct 2016, 01:10 AM
I checked to make sure that the xaml.cs file is the one that is connected to the usercontrol that I am loading, and it still isn't working as expected. The only thing I can think of is to allow access to my github repository so you have the full project available. 
0
Martin Ivanov
Telerik team
answered on 12 Oct 2016, 08:25 AM
Hi Tim,

Indeed, without your code I can't help. However, if you decide to share it in any way I would ask you to isolate the issue instead of sending the full application. This way it way the time spent for exploring your implementation and searching for the issue will be decreased. Also, I would ask you to exclude any Telerik dlls, especially if the storage service is public.  In addition, if you have an active support plan you can share your project as a .zip file in the ticketing system.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Tim
Top achievements
Rank 1
answered on 13 Oct 2016, 04:46 AM

Well, I have played with this quite a bit, and for some reason I just can't get it to change the IsExpanded state of the RadExpander except from the shell view or the shell viewmodel. Don't know.  It must be something to do with attempting to change it from a user control that is displayed inside a ContentControl.  

Anyway, i was able to find a workaround.  It's not perfect MVVM architecture, but hey... it works

 

I set up an event for MouseEnter on the header, and then another event of MouseLeave on the expander itself.   So  basically the expander opens when I mouseover the header, stays expanded while I select an item from the expanded menu, and then autohides when I leave the expander.

Code is below in case anyone is interested. 

 

private void ExpanderCaption_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
    MenuFlyOut.IsExpanded = true;
}
 
private void MenuFlyOut_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
{
    MenuFlyOut.IsExpanded = false;
}
0
Tim
Top achievements
Rank 1
answered on 13 Oct 2016, 04:55 AM

And before this thread is closed.... 

Thank you, Martin.  I appreciate the assistance, and the time you gave to help.  I see your responses all over these forums, and I just wanted to say that there are not many companies that provide this kind of resource even at the subscription level, and I, for one, am incredibly great-full for it.

Thank you, again!

0
Martin Ivanov
Telerik team
answered on 13 Oct 2016, 07:51 AM
Hello Tim,

I am glad to hear that you managed to resolve the issue on your side. I am also very happy that our forum is helpful for you and I hope for the rest of our community either. Thank you for the appreciation.

Regards,
Martin
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Expander
Asked by
Tim
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Tim
Top achievements
Rank 1
Share this question
or