瀏覽代碼

自定义控件

样式分支
pry 2 年之前
父節點
當前提交
45e12b665e
共有 5 個文件被更改,包括 78 次插入23 次删除
  1. +42
    -0
      BPASmartClient.CustomResource/Converters/StringToIconConverter.cs
  2. +4
    -1
      BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml
  3. +29
    -19
      BPASmartClient.CustomResource/UserControls/IcoButton.xaml
  4. +2
    -2
      BPASmartClient.CustomResource/UserControls/IcoButton.xaml.cs
  5. +1
    -1
      BPASmartClient/Control/ShopDeviceConfigView.xaml

+ 42
- 0
BPASmartClient.CustomResource/Converters/StringToIconConverter.cs 查看文件

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Windows.Data;
using System.Globalization;
using System.Text.RegularExpressions;

namespace BPASmartClient.CustomResource.Converters
{
public class StringToIconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
return Regex.Unescape(StringToUnicode(value.ToString()));
}
return value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

/// <summary>
/// 字符串转为UniCode码字符串
/// </summary>
public static string StringToUnicode(string s)
{
if (!string.IsNullOrEmpty(s))
{
//这里把格式&#xe625; 转为 \ue625
return s.Replace(@"&#x", @"\u").Replace(";", "");
}
return s;
}
}
}

+ 4
- 1
BPASmartClient.CustomResource/RecDictionarys/GlobalStyle.xaml 查看文件

@@ -1,4 +1,7 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- 文本框的字体颜色 -->
<SolidColorBrush x:Key="TextBlockForeground" Color="#9934F7F7" />
<!--<con:StringToIconConverter x:Key="StringToIconConverter"/>-->
</ResourceDictionary>

+ 29
- 19
BPASmartClient.CustomResource/UserControls/IcoButton.xaml 查看文件

@@ -2,6 +2,7 @@
x:Class="BPASmartClient.CustomResource.UserControls.IcoButton"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:con="clr-namespace:BPASmartClient.CustomResource.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.CustomResource.UserControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -52,35 +53,44 @@
</Setter>
</Style>
</UserControl.Resources>-->

<UserControl.Resources>
<con:StringToIconConverter x:Key="StringToIconConverter" />
</UserControl.Resources>

<Grid>
<!--<Canvas Width="auto" Height="auto">-->
<Button Name="a">
<!--<TextBlock
x:Name="tbx"
FontFamily="../Fonts/#iconfont"
Text="{Binding Path=IcoText, Mode=TwoWay, Converter={StaticResource StringToIconConverter}}" />-->

<TextBlock x:Name="tbx" Foreground="Red" FontSize="14" />
<!--<Button Name="a">
<Button.Style>
<Style TargetType="Button">
<Setter Property="FontFamily" Value="../Fonts/#iconfont" />
-->
<!--<Setter Property="FontFamily" Value="../Fonts/#iconfont" />-->
<!--
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border
x:Name="br"
Background="Transparent"
BorderBrush="#FF19B7EC"
BorderThickness="2">
x:Name="br"
Background="Transparent"
BorderBrush="#FF19B7EC"
BorderThickness="2">
<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock
Margin="0,0,5,0"
FontFamily="../Fonts/#iconfont"
Text="我是图标" />
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
-->
<!--<TextBlock FontFamily="../Fonts/#iconfont" Text="{Binding Path=IcoText, Converter={StaticResource StringToIconConverter}}" />-->
<!--
<ContentControl
Margin="10,0,5,0"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
Foreground="{TemplateBinding Foreground}" />
Margin="10,0,5,0"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
Foreground="{TemplateBinding Foreground}" />
</StackPanel>
</Border>
<ControlTemplate.Triggers>
@@ -98,7 +108,7 @@
</Setter>
</Style>
</Button.Style>
</Button>
</Button>-->
<!--</Canvas>-->
</Grid>
</UserControl>

+ 2
- 2
BPASmartClient.CustomResource/UserControls/IcoButton.xaml.cs 查看文件

@@ -32,7 +32,7 @@ namespace BPASmartClient.CustomResource.UserControls

private void Refresh()
{
tbx.Text = this.IcoText;
}

public int BorderThickness
@@ -52,7 +52,7 @@ namespace BPASmartClient.CustomResource.UserControls
}
public static readonly DependencyProperty IcoTextProperty =
DependencyProperty.Register("IcoText", typeof(string), typeof(IcoButton),
new PropertyMetadata("", new PropertyChangedCallback(OnPropertyChanged)));
new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnPropertyChanged)));

}
}

+ 1
- 1
BPASmartClient/Control/ShopDeviceConfigView.xaml 查看文件

@@ -102,7 +102,7 @@
VerticalAlignment="Center"
Content="新建"
Foreground="{StaticResource TextBlockForeground}"
IcoText="&#xe626;" />
IcoText="AA" />

<!--<Button
Width="140"


Loading…
取消
儲存