NewLife/XCoder

数据模板载入连接
BearXiongLaoXiong authored at 2020-08-21 18:19:28
979ebb4
Tree
1 Parent(s) 8f13782
Summary: 11 changed files with 128 additions and 148 deletions.
Modified +1 -0
Added +14 -0
Deleted +0 -9
XCoderWpf/Models/CardModel.cs
Added +16 -0
Added +0 -0
Added +0 -0
Added +0 -0
Added +71 -0
Modified +10 -41
Modified +9 -97
Modified +7 -1
Modified +1 -0
diff --git a/XCoderWpf/App.xaml b/XCoderWpf/App.xaml
index f28f20c..c83b6cf 100644
--- a/XCoderWpf/App.xaml
+++ b/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>
Added +14 -0
diff --git a/XCoderWpf/Common/Converaters/BoolToVisibilityConverter.cs b/XCoderWpf/Common/Converaters/BoolToVisibilityConverter.cs
new file mode 100644
index 0000000..da3e5c4
--- /dev/null
+++ b/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();
+    }
+}
Deleted +0 -9
XCoderWpf/Models/CardModel.cs
Added +16 -0
diff --git a/XCoderWpf/Models/DataBasePublishModel.cs b/XCoderWpf/Models/DataBasePublishModel.cs
new file mode 100644
index 0000000..68f5a05
--- /dev/null
+++ b/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; }
+    }
+}
Added +0 -0
diff --git a/XCoderWpf/Resources/Images/SqlServer/mssql.png b/XCoderWpf/Resources/Images/SqlServer/mssql.png
new file mode 100644
index 0000000..0d33c9f
Binary files /dev/null and b/XCoderWpf/Resources/Images/SqlServer/mssql.png differ
Added +0 -0
diff --git a/XCoderWpf/Resources/Images/SqlServer/mysql.png b/XCoderWpf/Resources/Images/SqlServer/mysql.png
new file mode 100644
index 0000000..3c48814
Binary files /dev/null and b/XCoderWpf/Resources/Images/SqlServer/mysql.png differ
Added +0 -0
diff --git a/XCoderWpf/Resources/Images/SqlServer/sqlite.png b/XCoderWpf/Resources/Images/SqlServer/sqlite.png
new file mode 100644
index 0000000..d35f6b6
Binary files /dev/null and b/XCoderWpf/Resources/Images/SqlServer/sqlite.png differ
Added +71 -0
diff --git a/XCoderWpf/Resources/Templates.xaml b/XCoderWpf/Resources/Templates.xaml
new file mode 100644
index 0000000..8d8e0ab
--- /dev/null
+++ b/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>
\ No newline at end of file
Modified +10 -41
diff --git a/XCoderWpf/ViewModels/DataBasePublishViewModel.cs b/XCoderWpf/ViewModels/DataBasePublishViewModel.cs
index 802d16f..0ac4607 100644
--- a/XCoderWpf/ViewModels/DataBasePublishViewModel.cs
+++ b/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"
+            }));
+           
         }
     }
 
Modified +9 -97
diff --git a/XCoderWpf/Views/DataBasePublish.xaml b/XCoderWpf/Views/DataBasePublish.xaml
index 141ebcc..0b42579 100644
--- a/XCoderWpf/Views/DataBasePublish.xaml
+++ b/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
Modified +7 -1
diff --git a/XCoderWpf/XCoderWpf.csproj b/XCoderWpf/XCoderWpf.csproj
index cd76110..5c7569c 100644
--- a/XCoderWpf/XCoderWpf.csproj
+++ b/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>