Commit e8649d39 authored by 潘栩锋's avatar 潘栩锋 🚴

添加 NoToggleButton 控件,用于不能触发IsChecked 的 button

parent 9bbbd8c5
......@@ -37,6 +37,28 @@ namespace FLY.ControlLibrary
} while (dobj != null);
return (T)dobj;
}
/// <summary>
/// 获取 DataContext
/// </summary>
/// <param name="dobj"></param>
/// <returns></returns>
public static object GetDataContext(DependencyObject dobj)
{
object dataContext = null;
do
{
if (dobj.GetType() == typeof(FrameworkElement))
{
dataContext = (dobj as FrameworkElement).DataContext;
if (dataContext != null)
{
break;
}
}
dobj = System.Windows.Media.VisualTreeHelper.GetParent(dobj);
} while (dobj != null);
return dataContext;
}
public static T GetParent<T>(DependencyObject dobj, string name) where T : FrameworkElement
{
do
......
......@@ -99,6 +99,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Rules\FileNameRule.cs" />
<Compile Include="NoToggleButton.cs" />
<Compile Include="WindowBigClose.cs" />
<Compile Include="UI.OSK\Window_FullPad.xaml.cs">
<DependentUpon>Window_FullPad.xaml</DependentUpon>
......@@ -151,22 +152,38 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Dictionary_MyStyle.xaml">
<Resource Include="Themes\ButtonStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Resource>
<Resource Include="Themes\Colors.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\MaterialDesignIcons.xaml">
<Generator>MSBuild:Compile</Generator>
</Resource>
<Resource Include="Themes\Dictionary_MyStyle.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</Resource>
<Resource Include="Themes\MaterialDesignIcons.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Resource>
<Resource Include="Themes\WindowBigCloseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Resource>
<Page Include="Themes\OfficeTab.xaml">
<Resource Include="Themes\OfficeTab.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</Resource>
<Resource Include="Themes\TextStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Resource>
<Resource Include="Themes\NoToggleButtonStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Resource>
<Page Include="UI.OSK\Window_FullPad.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace FLY.ControlLibrary
{
/// <summary>
/// 带IsChecked 的button, 不能通过点击 使IsChecked改变
/// </summary>
public class NoToggleButton : Button
{
/// <summary>
/// 显示的状态
/// </summary>
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(NoToggleButton));
/// <summary>
/// Off时的颜色
/// </summary>
public static readonly DependencyProperty OffBrushProperty = DependencyProperty.Register("OffBrush", typeof(Brush), typeof(NoToggleButton));
/// <summary>
/// On时的颜色
/// </summary>
public static readonly DependencyProperty OnBrushProperty = DependencyProperty.Register("OnBrush", typeof(Brush), typeof(NoToggleButton));
/// <summary>
/// Off时文字
/// </summary>
public static readonly DependencyProperty OffLabelProperty = DependencyProperty.Register("OffLabel", typeof(string), typeof(NoToggleButton));
/// <summary>
/// On时文字
/// </summary>
public static readonly DependencyProperty OnLabelProperty = DependencyProperty.Register("OnLabel", typeof(string), typeof(NoToggleButton));
public static bool GetIsChecked(UIElement element)
{
return (bool)element.GetValue(IsCheckedProperty);
}
public static void SetIsChecked(UIElement element, bool isClecked)
{
element.SetValue(IsCheckedProperty, isClecked);
}
public static Brush GetOffBrush(UIElement element)
{
return (Brush)element.GetValue(OffBrushProperty);
}
public static void SetOffBrush(UIElement element, Brush brush)
{
element.SetValue(OffBrushProperty, brush);
}
public static Brush GetOnBrush(UIElement element)
{
return (Brush)element.GetValue(OnBrushProperty);
}
public static void SetOnBrush(UIElement element, Brush brush)
{
element.SetValue(OnBrushProperty, brush);
}
public static string GetOnLabel(UIElement element)
{
return (string)element.GetValue(OnLabelProperty);
}
public static void SetOnLabel(UIElement element, string onLabel)
{
element.SetValue(OnLabelProperty, onLabel);
}
public static string GetOffLabel(UIElement element)
{
return (string)element.GetValue(OffLabelProperty);
}
public static void SetOffLabel(UIElement element, string offLabel)
{
element.SetValue(OffLabelProperty, offLabel);
}
public bool IsChecked
{
get
{
return (bool)GetValue(IsCheckedProperty);
}
set
{
SetValue(IsCheckedProperty, value);
}
}
public Brush OnBrush
{
get
{
return (Brush)GetValue(OnBrushProperty);
}
set
{
SetValue(OnBrushProperty, value);
}
}
public Brush OffBrush
{
get
{
return (Brush)GetValue(OffBrushProperty);
}
set
{
SetValue(OffBrushProperty, value);
}
}
public string OnLabel
{
get
{
return (string)GetValue(OnLabelProperty);
}
set
{
SetValue(OnLabelProperty, value);
}
}
public string OffLabel
{
get
{
return (string)GetValue(OffLabelProperty);
}
set
{
SetValue(OffLabelProperty, value);
}
}
}
}
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="Brush_theme_bar" Color="#C0008BE5"/>
<SolidColorBrush x:Key="Background_Title" Color="#C0008BE5"/>
<SolidColorBrush x:Key="Color_theme_activity" Color="#FF008BE5"/>
<SolidColorBrush x:Key="Color_theme_static" Color="#FF3B3B3B"/>
<SolidColorBrush x:Key="Color_theme_noact" Color="#FF888888"/>
<SolidColorBrush x:Key="Color_theme_background" Color="White"/>
<SolidColorBrush x:Key="Color_theme_text_activity" Color="DarkBlue"/>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:flyctrl="clr-namespace:FLY.ControlLibrary;assembly=FLY.ControlLibrary">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--toggleSwitchButton 默认样式-->
<Style TargetType="flyctrl:NoToggleButton" x:Key="NoToggleButtonStyle">
<Setter Property="Margin" Value="5"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Width" Value="110"/>
<Setter Property="OffBrush" Value="{StaticResource Color_theme_static}" />
<Setter Property="OnBrush" Value="{StaticResource Color_theme_activity}" />
<Setter Property="OffLabel" Value="{Binding Content,RelativeSource={RelativeSource Mode=Self}}" />
<Setter Property="OnLabel" Value="{Binding Content,RelativeSource={RelativeSource Mode=Self}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="flyctrl:NoToggleButton">
<Border x:Name="canvas" Height="55" Width="{TemplateBinding Width}" Background="{TemplateBinding OffBrush}">
<Grid>
<Rectangle x:Name="Path_block" Height="45" Width="24" Margin="5" Fill="White" HorizontalAlignment="Left"/>
<StackPanel x:Name="SP_Text" Orientation="Horizontal" Margin="20,15" HorizontalAlignment="Right">
<TextBlock x:Name="TB_OnOff" Text="{TemplateBinding Property=OffLabel}" Foreground="White" FontSize="24" FontFamily="YouYuan"/>
</StackPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Path_block" Property="HorizontalAlignment" Value="Right"/>
<Setter TargetName="SP_Text" Property="HorizontalAlignment" Value="Left"/>
<Setter TargetName="TB_OnOff" Property="Text" Value="{Binding OnLabel,RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
<Setter TargetName="canvas" Property="Background" Value="{Binding OnBrush,RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<!--块移到中间-->
<Setter TargetName="Path_block" Property="HorizontalAlignment" Value="Center"/>
<Setter TargetName="TB_OnOff" Property="Opacity" Value="0.5"/>
<Setter Property="Opacity" Value="1"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.7"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="flyctrl:NoToggleButton" BasedOn="{StaticResource NoToggleButtonStyle}"/>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:osk="clr-namespace:FLY.UI.OSK;assembly=FLY.ControlLibrary"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/FLY.ControlLibrary;component/Themes/Colors.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBox" x:Key="TextBoxStyle1">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border Name="PART_Border" BorderBrush="{TemplateBinding Foreground}" Background="{TemplateBinding Background}">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<i:Interaction.Behaviors>
<osk:KeyboardBehavior/>
</i:Interaction.Behaviors>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter TargetName="PART_Border" Property="BorderThickness" Value="1"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_FieldHeaderEditable">
<Setter Property="Margin" Value="3" />
<Setter Property="Foreground" Value="#FF0083D7" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="22" />
<Setter Property="FontFamily" Value="YouYuan" />
<Setter Property="TextAlignment" Value="Left" />
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_FieldHeader">
<Setter Property="Margin" Value="3" />
<Setter Property="Foreground" Value="#FF3B3B3B" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="22" />
<Setter Property="FontFamily" Value="YouYuan" />
<Setter Property="TextAlignment" Value="Left" />
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_ItemHeader">
<Setter Property="Margin" Value="0,9,0,0" />
<Setter Property="Foreground" Value="#FFFFFFFF" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="30" />
<Setter Property="FontFamily" Value="YouYuan" />
<Setter Property="TextAlignment" Value="Right" />
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_FieldContent">
<Setter Property="Margin" Value="3" />
<Setter Property="Foreground" Value="#FF3B3B3B" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="36" />
<Setter Property="FontFamily" Value="Microsoft Sans Serif" />
<Setter Property="TextAlignment" Value="Left" />
</Style>
<Style TargetType="TextBox" x:Key="TextBoxStyle_FieldContent" BasedOn="{StaticResource ResourceKey=TextBoxStyle1}">
<Setter Property="Margin" Value="3" />
<Setter Property="Foreground" Value="#FF3B3B3B" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="36" />
<Setter Property="FontFamily" Value="Microsoft Sans Serif" />
<Setter Property="TextAlignment" Value="Left" />
<Setter Property="MinWidth" Value="30" />
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_FieldContent_mm_interval">
<Setter Property="Foreground" Value="#FF888888" />
<Setter Property="FontSize" Value="36" />
<Setter Property="FontFamily" Value="Microsoft Sans Serif" />
<Setter Property="TextAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_FieldContent_mm">
<Setter Property="Foreground" Value="#FF888888" />
<Setter Property="FontSize" Value="22" />
<Setter Property="FontFamily" Value="Microsoft Sans Serif" />
<Setter Property="TextAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_Title">
<Setter Property="Margin" Value="160,0,0,0" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="60" />
<Setter Property="FontFamily" Value="YouYuan" />
<Setter Property="TextAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</ResourceDictionary>
\ No newline at end of file
......@@ -15,13 +15,14 @@
<ContentPresenter/>
</AdornerDecorator>
</Border>
<Button Name="button_close" Style="{StaticResource ButtonStyle_empty}" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5" Background="{x:Null}" BorderThickness="0" >
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" >
<Ellipse Fill="White" Height="110" Width="{Binding Height,RelativeSource={RelativeSource Mode=Self}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Path Data="{StaticResource Geometry_close-circle}" Fill="Red" Stretch="Fill" Height="100" Width="{Binding Height,RelativeSource={RelativeSource Mode=Self}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
<Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="5" Height="110" Width="{Binding Height,RelativeSource={RelativeSource Mode=Self}}" >
<Ellipse Fill="White" Stretch="Fill" />
<Button Name="button_close" Style="{StaticResource ButtonStyle_empty}" Margin="5" BorderThickness="0" >
<Path Data="{StaticResource Geometry_close-circle}" Fill="Red" Stretch="Fill" />
</Button>
</Grid>
</Grid>
</ControlTemplate>
<Style x:Key="WindowBigCloseStyle" TargetType="{x:Type Window}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment