Setting IsExpanded from a UserControl

7 posts, 0 answers
  1. Timothy
    Timothy avatar
    4 posts
    Member since:
    Oct 2016

    Posted 10 Oct Link to this post

    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.

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 11 Oct Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Timothy
    Timothy avatar
    4 posts
    Member since:
    Oct 2016

    Posted 11 Oct in reply to Martin Link to this post

    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. 
  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 12 Oct Link to this post

    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.
  6. Timothy
    Timothy avatar
    4 posts
    Member since:
    Oct 2016

    Posted 12 Oct Link to this post

    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;
    }
  7. Timothy
    Timothy avatar
    4 posts
    Member since:
    Oct 2016

    Posted 12 Oct in reply to Martin Link to this post

    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!

  8. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 13 Oct Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready