Browse Source

数据模板载入连接

net45
BearXiongLaoXiong 5 years ago
parent
commit
979ebb4395
  1. 1
      XCoderWpf/App.xaml
  2. 14
      XCoderWpf/Common/Converaters/BoolToVisibilityConverter.cs
  3. 9
      XCoderWpf/Models/CardModel.cs
  4. 16
      XCoderWpf/Models/DataBasePublishModel.cs
  5. BIN
      XCoderWpf/Resources/Images/SqlServer/mssql.png
  6. BIN
      XCoderWpf/Resources/Images/SqlServer/mysql.png
  7. BIN
      XCoderWpf/Resources/Images/SqlServer/sqlite.png
  8. 71
      XCoderWpf/Resources/Templates.xaml
  9. 51
      XCoderWpf/ViewModels/DataBasePublishViewModel.cs
  10. 106
      XCoderWpf/Views/DataBasePublish.xaml
  11. 8
      XCoderWpf/XCoderWpf.csproj

1
XCoderWpf/App.xaml

@ -8,6 +8,7 @@
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/SkinDefault.xaml"/>
<ResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Theme.xaml"/>
<ResourceDictionary Source="/Resources/Geometries.xaml"/>
<ResourceDictionary Source="/Resources/Templates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

14
XCoderWpf/Common/Converaters/BoolToVisibilityConverter.cs

@ -0,0 +1,14 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace XCoderWpf.Common.Converaters
{
public class BoolToVisibilityConverter : IValueConverter
{
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) => value != null && (Boolean)value ? Visibility.Visible : Visibility.Collapsed;
public Object ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) => throw new NotImplementedException();
}
}

9
XCoderWpf/Models/CardModel.cs

@ -1,9 +0,0 @@
namespace XCoderWpf.Models
{
public class CardModel
{
public string Header { get; set; }
public string Content { get; set; }
public string Footer { get; set; }
}
}

16
XCoderWpf/Models/DataBasePublishModel.cs

@ -0,0 +1,16 @@
using System;
namespace XCoderWpf.Models
{
public class DataBasePublishModel
{
}
public class ConnectionStringModel
{
public Uri IconSource { get; set; }
public string Title { get; set; }
public string Server { get; set; }
}
}

BIN
XCoderWpf/Resources/Images/SqlServer/mssql.png

After

Width: 32  |  Height: 32  |  Size: 1.3 KiB

BIN
XCoderWpf/Resources/Images/SqlServer/mysql.png

After

Width: 32  |  Height: 32  |  Size: 1.1 KiB

BIN
XCoderWpf/Resources/Images/SqlServer/sqlite.png

After

Width: 32  |  Height: 32  |  Size: 941 B

71
XCoderWpf/Resources/Templates.xaml

@ -0,0 +1,71 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:conver="clr-namespace:XCoderWpf.Common.Converaters">
<conver:BoolToVisibilityConverter x:Key="VisibilityConverter"/>
<DataTemplate x:Key="DataBaseItems">
<ContentControl>
<RadioButton GroupName="ConnectionStringGroup" Command="{Binding Command}" CommandParameter="{Binding}" Style="{x:Null}">
<RadioButton.Template>
<ControlTemplate TargetType="RadioButton">
<Border>
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="{DynamicResource DarkDefaultBrush}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=RadioButton}}" Value="True">
<Setter Property="Background" Value="#E6E6E6"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=RadioButton}}" Value="True">
<Setter Property="Background" Value="#CECDCD"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="45"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border Grid.RowSpan="2" Width="35" Height="35" BorderThickness="1" BorderBrush="{StaticResource BorderBrush}">
<Image Source="/Resources/Images/SqlServer/mysql.png" Stretch="UniformToFill" />
</Border>
<TextBlock Grid.Row="0" Grid.Column="1" Padding="0" Text="{Binding Title, FallbackValue='******'}" Foreground="{StaticResource PrimaryTextBrush}" />
<TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Padding="0" FontSize="10" Text="{Binding Server, FallbackValue='********'}" Foreground="{StaticResource BorderBrush}" />
<TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" Foreground="White" Text="已连接" Background="{StaticResource DarkDangerBrush}"
Visibility="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=RadioButton},UpdateSourceTrigger=PropertyChanged, Converter={StaticResource VisibilityConverter}}"/>
<!--<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Vertical" >
</StackPanel>-->
</Grid>
</Border>
</ControlTemplate>
</RadioButton.Template>
</RadioButton>
</ContentControl>
</DataTemplate>
<ControlTemplate x:Key="News" TargetType="ContentControl">
<Border BorderBrush="Black" BorderThickness="2" Background="White">
<DockPanel>
<Border BorderBrush="Black" BorderThickness="1,0,0,0" DockPanel.Dock="Right" Padding="4">
<TextBlock Text="{Binding Datetime,FallbackValue='*2019/12/12 0:00:00*'}" VerticalAlignment="Center"/>
</Border>
<StackPanel Orientation="Vertical" Margin="4">
<TextBlock Text="{Binding Title, FallbackValue='*标题*'}" FontSize="16" FontWeight="Bold"/>
<TextBlock Text="{Binding ReporterName, FallbackValue='*记者名称*'}"/>
</StackPanel>
</DockPanel>
</Border>
</ControlTemplate>
</ResourceDictionary>

51
XCoderWpf/ViewModels/DataBasePublishViewModel.cs

@ -6,6 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using Prism.Mvvm;
using XCode.DataAccessLayer;
using XCoderWpf.Models;
namespace XCoderWpf.ViewModels
{
@ -18,13 +19,10 @@ namespace XCoderWpf.ViewModels
set { SetProperty(ref _datalist, value); }
}
private ObservableCollection<MenuModel> menus;
private ObservableCollection<ConnectionStringModel> _connectionStringList;
/// <summary>菜单集合</summary>
public ObservableCollection<MenuModel> Menus
{
get => menus;
set { menus = value; RaisePropertyChanged(); }
}
public ObservableCollection<ConnectionStringModel> ConnectionStringList { get => _connectionStringList; set { SetProperty(ref _connectionStringList, value); } }
private MenuModel selectedMenu;
/// <summary>选中菜单</summary>
public MenuModel SelectedMenu
@ -36,42 +34,13 @@ namespace XCoderWpf.ViewModels
public DataBasePublishViewModel()
{
var list = DAL.ConnStrs.Keys.ToList();
DataList = new ObservableCollection<string>
ConnectionStringList = new ObservableCollection<ConnectionStringModel>(list.Select(x => new ConnectionStringModel
{
"mssql111",
"mssql112",
"mssql113",
"mssql114",
"mssql115",
"mssql1117",
};
Menus = new ObservableCollection<MenuModel>();
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "数据建模", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe6b6", Title = "网络工具", BackColor = "#EE3B3B" });
menus.Add(new MenuModel() { IconFont = "\xe6e1", Title = "RPC工具", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe614", Title = "串口工具", BackColor = "#EE3B3B" });
menus.Add(new MenuModel() { IconFont = "\xe755", Title = "地图接口", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "正则表达式", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe6b6", Title = "图标水印", BackColor = "#EE3B3B" });
menus.Add(new MenuModel() { IconFont = "\xe6e1", Title = "加密解密", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe614", Title = "语音助手", BackColor = "#EE3B3B" });
menus.Add(new MenuModel() { IconFont = "\xe755", Title = "文件夹统计", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "文件编码", BackColor = "#218868" });
menus.Add(new MenuModel() { IconFont = "\xe635", Title = "asdfasfasf", BackColor = "#218868" });
SelectedMenu = Menus[0];
Title = x,
IconSource = new Uri("/Resources/Images/SqlServer/mysql.png",UriKind.Relative),
Server = "192.168.102.1"
}));
}
}

106
XCoderWpf/Views/DataBasePublish.xaml

@ -4,78 +4,7 @@
xmlns:prism="http://prismlibrary.com/"
xmlns:hc="https://handyorg.github.io/handycontrol"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<Style x:Key="RadioButtonStyle" TargetType="{x:Type RadioButton}">
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0 2 0 0"/>
<Setter Property="FontSize" Value="26"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
<Border x:Name="border" BorderBrush="Red" BorderThickness="0" SnapsToDevicePixels="True"/>
<Border x:Name="bd2"/>
<ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}" Grid.Column="1"
ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasContent" Value="True">
<Setter Property="FocusVisualStyle">
<Setter.Value>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Margin="14,0,0,0" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="4,-1,0,0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#F7F7F7" TargetName="border"/>
</Trigger>
<Trigger Property="IsChecked" Value="true">
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="{Binding BackColor}"/>
<Setter Property="BorderThickness" Value="4 0 0 0" TargetName="bd2"/>
<Setter Property="BorderBrush" Value="{Binding BackColor}" TargetName="bd2"/>
<Setter Property="Background" Value="{Binding BackColor}" TargetName="border"/>
<Setter Property="Opacity" Value="0.05" TargetName="border"/>
</Trigger>
<Trigger Property="IsChecked" Value="{x:Null}"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="MinHeight" Value="44"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</UserControl.Resources>
<Grid Background="{DynamicResource BackgroundBrush}">
<Border Background="{DynamicResource RegionBrush}" Effect="{StaticResource EffectShadow4}" CornerRadius="16" Margin="10">
<Grid >
@ -89,31 +18,14 @@
<StackPanel >
<hc:SearchBar Margin="20,30,20,0" Style="{StaticResource SearchBarExtend}"/>
<hc:TransitioningContentControl Margin="20,10,20,0">
<ListBox Height="200" ItemsSource="{Binding Menus}" SelectedItem="{Binding SelectedMenu}" BorderThickness="0">
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton
CommandParameter="{Binding}">
<RadioButton.IsChecked>
<Binding Path="IsSelected" RelativeSource="{RelativeSource AncestorType=ListBoxItem}" Mode="TwoWay"/>
</RadioButton.IsChecked>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Column="0" Text="{Binding IconFont}" FontFamily="./Fonts/#iconfont" FontSize="22"
Margin="10 0 0 0" Foreground="Red"/>
<TextBlock Margin="10 0 0 0" Text="{Binding Title}" FontSize="14" VerticalAlignment="Center"
Foreground="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1,
AncestorType={x:Type RadioButton}}}" />
</StackPanel>
</RadioButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<hc:TransitioningContentControl Margin="20,10,20,0">
<ItemsControl ItemsSource="{Binding ConnectionStringList}" BorderThickness="1" BorderBrush="{StaticResource BorderBrush}" ItemTemplate="{StaticResource DataBaseItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</hc:TransitioningContentControl>
<TextBlock Margin="40,20,0,0" Foreground="White">
<Bold>提示</Bold>path

8
XCoderWpf/XCoderWpf.csproj

@ -2,16 +2,22 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\iconfont.ttf" />
<None Remove="Resources\Images\SqlServer\mssql.png" />
<None Remove="Resources\Images\SqlServer\mysql.png" />
<None Remove="Resources\Images\SqlServer\sqlite.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\iconfont.ttf" />
<Resource Include="Resources\Images\SqlServer\mssql.png" />
<Resource Include="Resources\Images\SqlServer\mysql.png" />
<Resource Include="Resources\Images\SqlServer\sqlite.png" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save