1.Xaml 继承Style 用属性BaseOn
2.DataTemplete
<Style TargetType="{x:Type ListBox}"> <Setter Property="ItemTemplate"> <Setter.Value> <DataTemplate DataType="{x:Type baseModel:FlowCheckDepRole}">
--摆放各个控件,形成想要的布局 <TextBlock Margin="10,5,0,0" Text="{Binding SpareName}" Height="25" Width="210" TextWrapping="Wrap"> </TextBlock> </DataTemplate> </Setter.Value> </Setter> </Style>
3.ControlTemplete
<Style TargetType="{x:Type Control}" x:Key="mm"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Border x:Name="Bd" BorderThickness="1" Background="White"> <ScrollViewer x:Name="Sv"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" TargetName="Bd" Value="White"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
4.WindowState = "Maximized" --最大化显示
5.Popup
<Button Background="Green" x:Name="btn" Click="btn_xianji_Click"/> <Popup x:Name="Pop_bg" PopupAnimation="Scroll" Width="88" Height="125" PlacementTarget="{Binding ElementName=btn}" Placement="Bottom" AllowsTransparency="False" StaysOpen="False" IsOpen="True" > </Popup> cs Pop_bg.IsOpen = true;
6.依赖属性 静态存储,性能和控件较传统属性都是很大的提升。外部调用时可使用绑定。第二个Typeof(DependencyObject) 实现绑定数据的双向变化。还可以写成所在类名,或所属控件
xmal
<local:UCButtonWithRedNum Grid.Row="2" x:Name="btnWaitCheck" NumText="{Binding Path=WaitCheckNum,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" ButtonClick="WaitCheck_Click"/>
cs
public static readonly DependencyProperty WaitCheckNumProperty = DependencyProperty.Register("WaitCheckNum", typeof(string), typeof(DependencyObject), new FrameworkPropertyMetadata(OnSelectedItemsChanged
, null));
public string WaitCheckNum
{
get => (string)GetValue(WaitCheckNumProperty);
set => SetValue(WaitCheckNumProperty, value);
}
private static void OnSelectedItemsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
UCMultiSelectComboBox control = (UCMultiSelectComboBox)d;
control.SelectNodes();
control.SetText();
}
7.依赖事件
xmal 如上一个xmal片段中的事件
ButtonClick="WaitCheck_Click"
cs
/// <summary>
/// 点击事件
/// </summary>
public event RoutedEventHandler WaitCheckClick
{
add => AddHandler(WaitCheckClickEvent, value);
remove => RemoveHandler(WaitCheckClickEvent, value);
}
/// <summary>
/// 点击事件
/// </summary>
public static readonly RoutedEvent WaitCheckClickEvent = EventManager.RegisterRoutedEvent(
"WaitCheckClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(UCFlowStatus));
private void WaitCheck_Click(object sender, RoutedEventArgs e)
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(WaitCheckClickEvent);
RaiseEvent(newEventArgs);
}