WPF SurfaceListBox SelectionChanged事件分析

图片预览:

xmal代码区:

<s:SurfaceWindow x:Class="Qv2._0.SurfaceWindow1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="http://schemas.microsoft.com/surface/2008"
    Title="Qv2._0"
    >
    <Grid Background="Transparent">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <s:SurfaceListBox Name="ContentSelector" Grid.Column="0"
                          SelectionChanged="OnSelectionChanged" Width="200" >       
            <s:SurfaceListBoxItem Content="item1" >
                <s:SurfaceListBoxItem.Tag>
                    <Grid>
                        <Button Width="200" Height="200">OK1</Button>
                        <Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="200" Height="200"
                                Click="Button_Click">返回</Button>
                    </Grid>
                </s:SurfaceListBoxItem.Tag>
            </s:SurfaceListBoxItem>

            <s:SurfaceListBoxItem Content="item2">
                <s:SurfaceListBoxItem.Tag>
                    <Grid>
                        <Button Width="200" Height="200">OK2</Button>
                        <Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="200" Height="200"
                                Click="Button_Click2">返回</Button>
                    </Grid>
                </s:SurfaceListBoxItem.Tag>
            </s:SurfaceListBoxItem>

            <s:SurfaceListBoxItem Content="item3">
                <s:SurfaceListBoxItem.Tag>
                    <Grid>
                        <Button Width="200" Height="200">OK3</Button>
                        <Button VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="200" Height="200"
                                Click="Button_Click3">返回</Button>
                    </Grid>
                </s:SurfaceListBoxItem.Tag>
            </s:SurfaceListBoxItem>
        </s:SurfaceListBox>          

    <Grid   Grid.Column="1" Background="Transparent" Name="ContentArea" Margin="7"/>
    </Grid>
</s:SurfaceWindow>

cs:代码片段

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SurfaceListBoxItem selectedItem = (SurfaceListBoxItem)ContentSelector.SelectedItem;
            Grid content = selectedItem.Tag as Grid;
            if (content != null)
            {

                ContentArea.Children.Clear();
                ContentArea.Children.Add(content);
                ContentSelector.Visibility = Visibility.Hidden;

            }
        }

    private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {

    //初始化
            SurfaceListBoxItem selectedItem = (SurfaceListBoxItem)ContentSelector.SelectedItem;
            Grid content = selectedItem.Tag as Grid;
            if (content != null)
            {

                ContentArea.Children.Clear();
                ContentArea.Children.Add(content);
                ContentSelector.Visibility = Visibility.Hidden;

            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ContentSelector.Visibility = Visibility.Visible;
          
        }
        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            ContentSelector.Visibility = Visibility.Visible;
           
        }
        private void Button_Click3(object sender, RoutedEventArgs e)
        {
            ContentSelector.Visibility = Visibility.Visible;         
        }

转载于:https://www.cnblogs.com/DeepBlues/archive/2013/02/25/2932383.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值