静态资源样式引用到自定义控件

This commit is contained in:
wule committed 2026-06-16 03:45:05 +08:00
1 parent 167885814e
commit 3fe394c8da
18 files changed
+191 -51

No files matched your search

+45 -12
View File
@@ -14,12 +14,27 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
@@ -75,11 +90,9 @@
<Compile Include="ToolCtrls\Icons.xaml.cs">
<DependentUpon>Icons.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\UcImageButton.xaml.cs">
<DependentUpon>UcImageButton.xaml</DependentUpon>
</Compile>
<Compile Include="UserControls\WindowBoxes.xaml.cs">
<DependentUpon>WindowBoxes.xaml</DependentUpon>
<Compile Include="UserControls\UcImageButton.cs" />
<Compile Include="UserControls\UcWindowBoxes.xaml.cs">
<DependentUpon>UcWindowBoxes.xaml</DependentUpon>
</Compile>
<Page Include="BaseWindows\BaseMsgWindow.xaml">
<SubType>Designer</SubType>
@@ -109,6 +122,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\StaticImageBrushDictionary.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\StaticImageDictionary.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\UcImageButtonStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -117,11 +138,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\UcImageButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControls\WindowBoxes.xaml">
<Page Include="UserControls\UcWindowBoxes.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@@ -152,7 +169,18 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.2 %28x86 和 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AllBase\29WxOrderAllBase.csproj">
<Project>{6461D807-B1C8-45F0-B388-E0CA1A418DE0}</Project>
@@ -179,5 +207,10 @@
<Resource Include="Resources\WindowBoxes\normal.hover.png" />
<Resource Include="Resources\WindowBoxes\normal.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\BaseMsgErr.png" />
<Resource Include="Resources\BaseMsgInfo.png" />
<Resource Include="Resources\BaseMsgQue.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory>publish\</PublishUrlHistory>
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>zh-CN</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>
+2
View File
@@ -6,6 +6,8 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles/StaticImageBrushDictionary.xaml" />
<ResourceDictionary Source="Styles/StaticImageDictionary.xaml" />
<ResourceDictionary Source="Styles/UcImageButtonStyle.xaml" />
<ResourceDictionary Source="Styles/BaseWindowStyle.xaml" />
<!-- 可以添加更多资源字典 -->
+19 -2
View File
@@ -5,14 +5,31 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_29WxOrderWpf.BaseWindows"
mc:Ignorable="d" Style="{StaticResource BaseNoneBorderWindowStyle}"
Title="BaseMsgWindow" Height="450" Width="800">
Title="BaseMsgWindow" Height="250" Width="350">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<userctrols:WindowBoxes VerticalAlignment="Center" HorizontalAlignment="Right" Margin="4" MinBoxVisibility="Collapsed" MaxBoxVisibility="Collapsed"/>
<Label x:Name="lblTitle" Margin="2,2" Foreground="White" Content="title"></Label>
<userctrols:UcWindowBoxes VerticalAlignment="Center" HorizontalAlignment="Right" Margin="4" MinBoxVisibility="Collapsed" MaxBoxVisibility="Collapsed"/>
<Border Margin="2,0,2,2" Grid.Row="1" Background="White">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image x:Name="imgTip" Source="{StaticResource imgBaseMsgInfo}" Stretch="Uniform" Width="64" Height="64" VerticalAlignment="Top" Margin="0,30" />
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
</Grid.RowDefinitions>
<Label x:Name="lblMsg" Content="message" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,30,30,30"/>
<Button x:Name="btnCancel" Content="取消" HorizontalAlignment="Right" Margin="0,20,30,0" Grid.Row="1" VerticalAlignment="Top" Width="75" Height="26" Click="btnCancel_Click"/>
<Button x:Name="btnOk" Content="确定" HorizontalAlignment="Right" Margin="0,20,130,0" Grid.Row="1" VerticalAlignment="Top" Width="75" Height="26" Click="btnOk_Click"/>
</Grid>
</Grid>
</Border>
</Grid>
</local:BaseWindow>
@@ -24,5 +24,55 @@ namespace _29WxOrderWpf.BaseWindows
InitializeComponent();
this.DataContext = this;
}
private static BaseMsgWindow CreateMsgForm(string msg, string caption, MsgWindowLevel fl)
{
BaseMsgWindow msgBox = new BaseMsgWindow { lblTitle = { Content = caption }, lblMsg = { Content = msg } };
if (fl.Equals(MsgWindowLevel.LARGE))
{
msgBox.Width = (int)MsgWindowLevel.LARGE;
msgBox.Height = 500;
}
msgBox.btnOk.Margin = new Thickness(msgBox.btnCancel.Margin.Left, msgBox.btnCancel.Margin.Top, msgBox.btnCancel.Margin.Right, msgBox.btnCancel.Margin.Bottom); // 把确认按钮移到取消按钮上面
msgBox.btnCancel.Visibility = Visibility.Collapsed;
return msgBox;
}
public static BaseMsgWindow ShowConfirm(Window window, string msg, string caption = "", MsgWindowLevel fl = MsgWindowLevel.MEDIUM)
{
string title = string.IsNullOrEmpty(caption) ? "确认系统提示" : caption;
BaseMsgWindow msgBox = new BaseMsgWindow
{
lblTitle = { Content = title },
lblMsg = { Content = msg },
imgTip = { Source = Application.Current.Resources["imgBaseMsgQue"] as ImageSource },
};
if (fl.Equals(MsgWindowLevel.LARGE))
{
msgBox.Width = (int)MsgWindowLevel.LARGE;
msgBox.Height = 500;
}
if (window != null)
msgBox.Owner = window;
msgBox.ShowDialog();
return msgBox;
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
}
public enum MsgWindowLevel
{
SMALL,
MEDIUM,
LARGE = 500
}
}
+1 -1
View File
@@ -15,6 +15,6 @@
<Grid Grid.Row="1" Margin="2,0,2,2" Background="White">
</Grid>
<userctrls:WindowBoxes VerticalAlignment="Top" HorizontalAlignment="Right" Margin="4" MaxBoxVisibility="Collapsed" MinBoxVisibility="Collapsed"/>
<userctrls:UcWindowBoxes VerticalAlignment="Top" HorizontalAlignment="Right" Margin="4" MaxBoxVisibility="Collapsed" MinBoxVisibility="Collapsed"/>
</Grid>
</basewindows:BaseWindow>
@@ -29,8 +29,15 @@ namespace _29WxOrderWpf.LoginWindows
private void BaseWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (BaseMsgForm.ShowConfirm("是否关闭软件?\r\n必须登录账户才能使用,无账户请先注册一个", "请先登录或者注册").DialogResult == System.Windows.Forms.DialogResult.OK)
//if (BaseMsgForm.ShowConfirm("是否关闭软件?\r\n必须登录账户才能使用,无账户请先注册一个", "请先登录或者注册").DialogResult == System.Windows.Forms.DialogResult.OK)
// Process.GetCurrentProcess().Kill();
//else
// e.Cancel = true;
if (BaseMsgWindow.ShowConfirm(this, "是否关闭软件?\r\n必须登录账户才能使用,无账户请先注册一个", "请先登录或者注册").DialogResult == true)
Process.GetCurrentProcess().Kill();
else
e.Cancel = true;
}
}
}
+1 -4
View File
@@ -14,12 +14,9 @@
<RowDefinition Height="60"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<!--<Border Grid.RowSpan="10" BorderThickness="1" BorderBrush="Blue">
</Border>-->
<Grid x:Name="gridContainer" Grid.Row="1" Background="White" Margin="2,0,2,2">
<orderctrls:OrderListWindow x:Name="OrderListWindow" Visibility="Hidden"></orderctrls:OrderListWindow>
</Grid>
<uc:WindowBoxes VerticalAlignment="Top" HorizontalAlignment="Right" Margin="4" MaxBoxVisibility="Visible"/>
<!--<Button Grid.Row="0" Content="x" HorizontalAlignment="Right" Margin="4" VerticalAlignment="Top" Width="20" Height="20" Click="btnClose_Click"/>-->
<uc:UcWindowBoxes VerticalAlignment="Top" HorizontalAlignment="Right" Margin="4" MaxBoxVisibility="Visible"/>
</Grid>
</basewindows:BaseWindow>
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

+4 -3
View File
@@ -4,14 +4,16 @@
<Style x:Key="BaseWindowStyle" TargetType="Window">
<Setter Property="Background" Value="#FF98638f"/>
<Setter Property="Foreground" Value="#FF666666"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontSize" Value="14"/>
<!-- 其他样式设置 -->
</Style>
<Style x:Key="BaseNoneBorderWindowStyle" TargetType="Window">
<Setter Property="Background" Value="#FF98638f"/>
<Setter Property="BorderBrush" Value="#6b5393"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="#FF666666"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontSize" Value="14"/>
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency" Value="True"/>
</Style>
@@ -28,7 +30,6 @@
</Setter.Value>
</Setter>
</Style>-->
<!--<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
@@ -0,0 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ImageBrush x:Key="imgBrushClose" ImageSource="/Resources/WindowBoxes/close.png" Stretch="Uniform"/>
<ImageBrush x:Key="imgBrushCloseHover" ImageSource="/Resources/WindowBoxes/close.hover.png" Stretch="Uniform"/>
</ResourceDictionary>
@@ -0,0 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="imgMin" UriSource="/Resources/WindowBoxes/min.png"/>
<BitmapImage x:Key="imgMinHover" UriSource="/Resources/WindowBoxes/min.hover.png"/>
<BitmapImage x:Key="imgNormal" UriSource="/Resources/WindowBoxes/normal.png"/>
<BitmapImage x:Key="imgNormalHover" UriSource="/Resources/WindowBoxes/normal.hover.png"/>
<BitmapImage x:Key="imgMax" UriSource="/Resources/WindowBoxes/max.png"/>
<BitmapImage x:Key="imgMaxHover" UriSource="/Resources/WindowBoxes/max.hover.png"/>
<BitmapImage x:Key="imgClose" UriSource="/Resources/WindowBoxes/close.png"/>
<BitmapImage x:Key="imgCloseHover" UriSource="/Resources/WindowBoxes/close.hover.png"/>
<BitmapImage x:Key="imgBaseMsgErr" UriSource="/Resources/BaseMsgErr.png"/>
<BitmapImage x:Key="imgBaseMsgInfo" UriSource="/Resources/BaseMsgInfo.png"/>
<BitmapImage x:Key="imgBaseMsgQue" UriSource="/Resources/BaseMsgQue.png"/>
</ResourceDictionary>
@@ -5,24 +5,14 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace _29WxOrderWpf.UserControls
{
/// <summary>
/// UcImageButton.xaml 的交互逻辑
/// </summary>
public partial class UcImageButton : Button
public class UcImageButton : Button
{
public UcImageButton()
{
InitializeComponent();
this.DataContext = this;
}
@@ -1,8 +0,0 @@
<Button x:Class="_29WxOrderWpf.UserControls.UcImageButton"
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:_29WxOrderWpf.UserControls"
mc:Ignorable="d" Width="30" Height="22">
</Button>
@@ -1,18 +1,36 @@
<UserControl x:Class="_29WxOrderWpf.UserControls.WindowBoxes"
<UserControl x:Class="_29WxOrderWpf.UserControls.UcWindowBoxes"
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:_29WxOrderWpf.UserControls"
mc:Ignorable="d" Width="Auto" Height="Auto"
d:DesignHeight="50" d:DesignWidth="300" Background="Black" Loaded="WindowBoxes_Loaded">
<Grid>
d:DesignHeight="50" d:DesignWidth="300" Background="Transparent" Loaded="WindowBoxes_Loaded">
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<!--<Border Background="{StaticResource imgBrushCloseHover}" Width="17" Height="17" Margin="4">
</Border>
<Border Grid.Column="1" Width="17" Height="17" Margin="4">
<Image Source="{StaticResource imgCloseHover}"/>
</Border>-->
<!--不使用静态资源,在用户控件嵌套时,会发生预览错误-->
<local:UcImageButton x:Name="btnMin" Grid.Column="0" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4"
ButtonImage="{StaticResource imgMin}" MouseOverButtonImage="{StaticResource imgMinHover}" MousePressButtonImage="{StaticResource imgMinHover}"/>
<local:UcImageButton x:Name="btnMax" Grid.Column="1" Width="17" Height="17" Background="Transparent" BorderThickness="0" Visibility="Collapsed" Margin="4"
ButtonImage="{StaticResource imgMax}" MouseOverButtonImage="{StaticResource imgMaxHover}" MousePressButtonImage="{StaticResource imgMaxHover}"/>
<local:UcImageButton x:Name="btnNormal" Grid.Column="2" Width="17" Height="17" Background="Transparent" BorderThickness="0" Visibility="Collapsed" Margin="4"
ButtonImage="{StaticResource imgNormal}" MouseOverButtonImage="{StaticResource imgNormalHover}" MousePressButtonImage="{StaticResource imgNormalHover}"/>
<local:UcImageButton x:Name="btnClose" Grid.Column="3" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4"
ButtonImage="{StaticResource imgClose}" MouseOverButtonImage="{StaticResource imgCloseHover}" MousePressButtonImage="{StaticResource imgCloseHover}"/>
<!--<local:UcImageButton x:Name="btnMin" Grid.Column="0" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4"
ButtonImage="/Resources/WindowBoxes/min.png"
MouseOverButtonImage="/Resources/WindowBoxes/min.hover.png"
@@ -29,8 +47,9 @@
ButtonImage="/Resources/WindowBoxes/close.png"
MouseOverButtonImage="/Resources/WindowBoxes/close.hover.png"
MousePressButtonImage="/Resources/WindowBoxes/close.hover.png" />-->
<Button x:Name="btnMin" Grid.Column="0" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4">
<!--<Button x:Name="btnMin" Grid.Column="0" Width="17" Height="17" Background="Transparent" BorderThickness="0" Margin="4">
<Border>
<Grid>
<Image Source="/Resources/WindowBoxes/min.png" Stretch="Uniform"/>
@@ -61,6 +80,6 @@
<Image Source="/Resources/WindowBoxes/close.hover.png" Stretch="Uniform" Visibility="Hidden"></Image>
</Grid>
</Border>
</Button>
</Button>-->
</Grid>
</UserControl>
@@ -18,10 +18,10 @@ namespace _29WxOrderWpf.UserControls
/// <summary>
/// WindowBox.xaml 的交互逻辑
/// </summary>
public partial class WindowBoxes : UserControl
public partial class UcWindowBoxes : UserControl
{
public static readonly DependencyProperty MaxBoxVisibilityProperty =
DependencyProperty.Register("MaxBoxVisibility", typeof(Visibility), typeof(WindowBoxes),
DependencyProperty.Register("MaxBoxVisibility", typeof(Visibility), typeof(UcWindowBoxes),
new PropertyMetadata(default(Visibility)));
public Visibility MaxBoxVisibility
{
@@ -34,7 +34,7 @@ namespace _29WxOrderWpf.UserControls
}
public static readonly DependencyProperty MinBoxVisibilityProperty =
DependencyProperty.Register("MinBoxVisibility", typeof(Visibility), typeof(WindowBoxes),
DependencyProperty.Register("MinBoxVisibility", typeof(Visibility), typeof(UcWindowBoxes),
new PropertyMetadata(default(Visibility)));
public Visibility MinBoxVisibility
{
@@ -42,7 +42,7 @@ namespace _29WxOrderWpf.UserControls
set { SetValue(MinBoxVisibilityProperty, value); btnMin.Visibility = value; }
}
public WindowBoxes()
public UcWindowBoxes()
{
InitializeComponent();
this.DataContext = this;