WPF用户控件选择器

时间:2018-07-31 15:34:01

标签: c# wpf

作为WPF的一席之地....

我正在尝试切换用户控件。 目前,我的代码正在使用“ new”来获取用户控制对象,但是这是一个非常有问题的原因,因为该代码已被读取很多次且对象没有释放,我使用的是非常弱的硬件。

还有其他方法可以在用户控件之间切换吗?

我的xaml文件看起来就是这样

<UserControl x:Uid="UserControl_1" x:Class="ddd.WindowFooter"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ddd"
             xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:Core="clr-namespace:Microsoft.Expression.Interactivity.Core" 
             xmlns:ddd="clr-namespace:ddd" 
             xmlns:Core1="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             DataContext="{Binding Source={StaticResource _indicatorSelector}}" KeyboardNavigation.TabNavigation="None">

    <Border x:Uid="Border_1" HorizontalAlignment="Left" VerticalAlignment="Bottom" CornerRadius="0,10,0,0" Background="{Binding Background}">
        <StackPanel x:Uid="StackPanel_1"  Margin="10,10,10,0">
            <Grid x:Uid="Grid_1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition x:Uid="ColumnDefinition_1" />
                <ColumnDefinition x:Uid="ColumnDefinition_2" />
            </Grid.ColumnDefinitions>

            <ContentControl x:Uid="contentControl1" Content="{Binding Slot1Control}" MouseDown="DoMouseDown"
                Height="40" Name="contentControl1" Width="100"  Grid.Column="0" />

                <ContentControl x:Uid="contentControl2" Content="{Binding Slot2Control}"  MouseLeftButtonUp="DoMouseDown" 
            </Grid>

        <Grid x:Uid="Grid_2" Grid.Row="1" Width="200" Height="22" Margin="0,7" HorizontalAlignment="Left" VerticalAlignment="Bottom">
            <Viewbox x:Uid="Viewbox_1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="Uniform">
                <ContentControl x:Uid="ContentControl_1" HorizontalAlignment="Left" VerticalAlignment="Top" ContentTemplate="{StaticResource SomeImage}" />
            </Viewbox>
        </Grid>
        </StackPanel>
    </Border>
</UserControl>

CS多数民众赞成在这样

public class IndicatorSelector : INotifyPropertyChanged
{
    UserControl Slot1Control{
        get
        {
            return new Slot1UserControl();
        }
    }

    UserControl Slot2Control{
        get
        {
            return new Slot2UserControl();
        }
    }
}

谢谢

0 个答案:

没有答案
相关问题