locked
Expander control doesn't display content RRS feed

  • Question

  • Hi,

    I've created an expander control to display some listviews and buttons when a toggle button is clicked. They will be displayed in a content presenter. I followed the example exactly as shown in this link:

    http://www.codeproject.com/Articles/562070/Expander-user-control-for-Windows-Metro-Style-app

    When the toggle button is clicked, nothing is being displayed. Can anyone point out what went wrong with my coding? 

    Here's the code:

    <Grid VerticalAlignment="Top">
        <Grid Background="#FF66A1AE">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="50"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                 <RowDefinition Height="50"/>
                 <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
    
            <TextBlock Grid.Column="0" Grid.Row="0" Margin="15,0,0,0" VerticalAlignment="Center" Text="{Binding ExpanderHeader, ElementName=userControl}"/>
            <ToggleButton x:Name="toggleButton" Grid.Column="1" Grid.Row="0"/>
            <ContentControl  Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Center" Width="Auto" Height="Auto" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=toggleButton}">
            <ContentPresenter/>
            </ContentControl>
        </Grid>
    </Grid>

    Thanks.

    Regards,

    Nafza


    • Edited by Nafza Monday, August 19, 2013 3:01 PM Link Added
    Monday, August 19, 2013 2:59 PM

Answers

  • Hi Nafza ,

    Welcome to MSDN forum!

    According to your description, I think you should code <ContentPresenter/> like below:

    <ContentPresenter Content="{Binding ExpanderContent, ElementName=userControl}"/>

    And it works well on my computer.

    Best Regards!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Nafza Wednesday, August 21, 2013 7:33 AM
    Tuesday, August 20, 2013 2:09 AM
    Moderator
  • Hi Nafza ,

    Welcome back!

    Please don't set "Grid.Column='1'" in <ContentControl> element.

    Zhe sample code:

    <ContentControl  Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Center" Width="Auto" Height="Auto" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=toggleButton}">
                    <ContentPresenter Content="{Binding ExpanderContent, ElementName=userControl}"/>
                </ContentControl>

    Best Regards!

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, August 21, 2013 1:40 AM
    Moderator

All replies

  • Hi Nafza ,

    Welcome to MSDN forum!

    According to your description, I think you should code <ContentPresenter/> like below:

    <ContentPresenter Content="{Binding ExpanderContent, ElementName=userControl}"/>

    And it works well on my computer.

    Best Regards!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Nafza Wednesday, August 21, 2013 7:33 AM
    Tuesday, August 20, 2013 2:09 AM
    Moderator
  • Hi Xiaoliang,

    Thanks for your reply. It works great! 

    However, the buttons and listview are not in the proper alignment. When I click the toggle button, they appear at the right most of the content area. It is not positioned nicely as depicted in the example. Does this have to do with the mainpage.xaml codings?

    Thanks. 

    Regards, 

    Nafza

    Tuesday, August 20, 2013 2:43 PM
  • Hi Nafza ,

    Welcome back!

    Please don't set "Grid.Column='1'" in <ContentControl> element.

    Zhe sample code:

    <ContentControl  Grid.Row="1" Grid.ColumnSpan="2" VerticalAlignment="Center" Width="Auto" Height="Auto" Visibility="{Binding IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=toggleButton}">
                    <ContentPresenter Content="{Binding ExpanderContent, ElementName=userControl}"/>
                </ContentControl>

    Best Regards!

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, August 21, 2013 1:40 AM
    Moderator
  • Hi XiaoLiang,

    Thanks for your reply. It works fine!

    I should have noticed that minor mistake.

    Anyway, thanks for pointing it out! Appreciate the help.


    • Edited by Nafza Wednesday, August 21, 2013 7:33 AM Edit
    Wednesday, August 21, 2013 7:32 AM