我得到了这个具有下拉菜单的应用程序,它改变了由大量小的相同用户控件组成的大用户控件(BW1)。现在我将所有用户控件转移到一个dll(在我用皮肤解析之前)。所以这是最大的用户控制:
<UserControl
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:WpfControlLibrary1" x:Class="WpfControlLibrary1.BW1"
mc:Ignorable="d"
d:DesignHeight="1028" d:DesignWidth="1280">
<UserControl.Resources>
<Style x:Key="SUC" TargetType="{x:Type local:SW1}">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Margin" Value="2,2,2,2"/>
</Style>
</UserControl.Resources>
<Grid Background="Black">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<local:SW1 x:Name="d11" Grid.Column="1" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d10" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d01" Grid.Column="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d02" Grid.Column="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d03" Grid.Column="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d04" Grid.Column="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d05" Grid.Column="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d06" Grid.Column="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d07" Grid.Column="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d08" Grid.Column="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d09" Grid.Column="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d12" Grid.Column="2" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d13" Grid.Column="3" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d14" Grid.Column="4" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d15" Grid.Column="5" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d16" Grid.Column="6" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d17" Grid.Column="7" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d18" Grid.Column="8" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d19" Grid.Column="9" Grid.Row="1" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d20" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d21" Grid.Column="1" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d22" Grid.Column="2" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d23" Grid.Column="3" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d24" Grid.Column="4" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d25" Grid.Column="5" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d26" Grid.Column="6" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d27" Grid.Column="7" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d28" Grid.Column="8" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d29" Grid.Column="9" Grid.Row="2" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d30" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d31" Grid.Column="1" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d32" Grid.Column="2" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d33" Grid.Column="3" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d34" Grid.Column="4" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d35" Grid.Column="5" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d36" Grid.Column="6" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d37" Grid.Column="7" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d38" Grid.Column="8" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d39" Grid.Column="9" Grid.Row="3" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d40" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d41" Grid.Column="1" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d42" Grid.Column="2" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d43" Grid.Column="3" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d44" Grid.Column="4" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d45" Grid.Column="5" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d46" Grid.Column="6" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d47" Grid.Column="7" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d48" Grid.Column="8" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d49" Grid.Column="9" Grid.Row="4" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d50" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d51" Grid.Column="1" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d52" Grid.Column="2" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d53" Grid.Column="3" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d54" Grid.Column="4" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d55" Grid.Column="5" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d56" Grid.Column="6" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d57" Grid.Column="7" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d58" Grid.Column="8" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d59" Grid.Column="9" Grid.Row="5" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d60" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d61" Grid.Column="1" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d62" Grid.Column="2" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d63" Grid.Column="3" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d64" Grid.Column="4" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d65" Grid.Column="5" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d66" Grid.Column="6" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d67" Grid.Column="7" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d68" Grid.Column="8" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d69" Grid.Column="9" Grid.Row="6" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d70" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d71" Grid.Column="1" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d72" Grid.Column="2" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d73" Grid.Column="3" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d74" Grid.Column="4" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d75" Grid.Column="5" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d76" Grid.Column="6" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d77" Grid.Column="7" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d78" Grid.Column="8" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d79" Grid.Column="9" Grid.Row="7" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d80" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d81" Grid.Column="1" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d82" Grid.Column="2" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d83" Grid.Column="3" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d84" Grid.Column="4" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d85" Grid.Column="5" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d86" Grid.Column="6" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d87" Grid.Column="7" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d88" Grid.Column="8" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d89" Grid.Column="9" Grid.Row="8" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d90" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d91" Grid.Column="1" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d92" Grid.Column="2" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d93" Grid.Column="3" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d94" Grid.Column="4" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d95" Grid.Column="5" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d96" Grid.Column="6" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d97" Grid.Column="7" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d98" Grid.Column="8" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
<local:SW1 x:Name="d99" Grid.Column="9" Grid.Row="9" Style="{StaticResource SUC}" Stroke="red"/>
</Grid>
现在我想在不更改布局的情况下将动态小的用户控件SW1更改为SW2或SW3(均来自同一个dll)。现在有什么方法可以做到这一点,而不是重新制作mvvm中的整个应用程序?
答案 0 :(得分:0)
如果你真的不想使用MVVM,你可以命名你的Grid
然后从你的代码中换掉控件:
<Grid Name="YourGrid" Background="Black">
...
</Grid>
然后在代码背后:
// Repeat as necessary
YourGrid.Children.RemoveAt(indexOfControlToRemove);
SW2 sw2 = new SW2();
sw2.SetValue(Grid.RowProperty, 1);
sw2.SetValue(Grid.ColumnProperty, 2);
YourGrid.Children.Add(sw2);