尝试从usercontrol获取属性
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
mc:Ignorable="d"
|
||||
>
|
||||
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top">
|
||||
<ListBox x:Name="IconfontList" ItemsSource="{Binding}" BorderThickness="0" Background="AliceBlue">
|
||||
<ListBox x:Name="IconListBox" ItemsSource="{Binding iconListSystem}" SelectionChanged="ListBox_SelectionChanged" BorderThickness="0" Background="AliceBlue">
|
||||
<ListBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel Orientation="Horizontal" Background="Transparent"/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using GeekDesk.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -25,5 +26,37 @@ namespace GeekDesk.Control.UserControls.IconFont
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconfontListProperty = DependencyProperty.Register("IconfontList", typeof(List<IconfontInfo>), typeof(IconPannel));
|
||||
public List<IconfontInfo> IconfontList
|
||||
{
|
||||
get
|
||||
{
|
||||
return (List<IconfontInfo>)GetValue(IconfontListProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(IconfontListProperty, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconInfoProperty = DependencyProperty.Register("IconInfo", typeof(IconfontInfo), typeof(IconPannel));
|
||||
|
||||
public IconfontInfo IconInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return (IconfontInfo)GetValue(IconInfoProperty);
|
||||
}
|
||||
set
|
||||
{
|
||||
SetValue(IconInfoProperty, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
IconfontInfo info = IconfontList[IconListBox.SelectedIndex];
|
||||
IconInfo = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
<hc:TabControl x:Name="MyTabControl" IsAnimationEnabled="True" SelectionChanged="TabControl_SelectionChanged" ShowContextMenu="True" IsTabFillEnabled="True" Margin="20,30,20,20" Height="350" VerticalAlignment="Top">
|
||||
<hc:TabItem Tag="System" Header="系统" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}" >
|
||||
<hc:SimplePanel Background="AliceBlue">
|
||||
<uc:IconPannel x:Name="System" />
|
||||
<uc:IconPannel IconfontList="{Binding iconListSystem}" IconInfo="{Binding iconInfoSystem}"/>
|
||||
</hc:SimplePanel>
|
||||
</hc:TabItem>
|
||||
<hc:TabItem Tag="Custom" IsSelected="True" Header="自定义" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}">
|
||||
<hc:SimplePanel Background="AliceBlue">
|
||||
<uc:IconPannel x:Name="Custom" />
|
||||
<uc:IconPannel IconfontList="{Binding iconListCustom}" IconInfo="{Binding iconInfoCustom}"/>
|
||||
</hc:SimplePanel>
|
||||
</hc:TabItem>
|
||||
</hc:TabControl>
|
||||
|
||||
@@ -22,16 +22,19 @@ namespace GeekDesk.Control.Windows
|
||||
public partial class IconfontWindow : Window
|
||||
{
|
||||
|
||||
private static List<IconfontInfo> listInfo;
|
||||
private static MenuInfo menuInfo;
|
||||
private DataContextInfo dataContextInfo = new DataContextInfo();
|
||||
|
||||
private IconfontWindow(List<IconfontInfo> listInfo, MenuInfo menuInfo)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = listInfo;
|
||||
IconfontWindow.listInfo = listInfo;
|
||||
dataContextInfo.iconListSystem = listInfo;
|
||||
this.DataContext = dataContextInfo;
|
||||
IconfontWindow.menuInfo = menuInfo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 移动窗口
|
||||
/// </summary>
|
||||
@@ -52,7 +55,7 @@ namespace GeekDesk.Control.Windows
|
||||
|
||||
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
this.DataContext = listInfo;
|
||||
//this.DataContext = listInfo;
|
||||
}
|
||||
|
||||
private void Confirm_Click(object sender, RoutedEventArgs e)
|
||||
@@ -62,15 +65,15 @@ namespace GeekDesk.Control.Windows
|
||||
switch (tag)
|
||||
{
|
||||
case "Custom":
|
||||
if (Custom.IconfontList.SelectedIndex != -1)
|
||||
if (dataContextInfo.iconInfoCustom != null)
|
||||
{
|
||||
menuInfo.MenuGeometry = (((StackPanel)Custom.IconfontList.SelectedItem).Tag as IconfontInfo).Text;
|
||||
menuInfo.MenuGeometry = dataContextInfo.iconInfoCustom.Text;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (System.IconfontList.SelectedIndex != -1)
|
||||
if (dataContextInfo.iconInfoSystem != null)
|
||||
{
|
||||
menuInfo.MenuGeometry = (((StackPanel)System.IconfontList.SelectedItem).Tag as IconfontInfo).Text;
|
||||
menuInfo.MenuGeometry = dataContextInfo.iconInfoSystem.Text;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -87,5 +90,16 @@ namespace GeekDesk.Control.Windows
|
||||
}
|
||||
window.Show();
|
||||
}
|
||||
|
||||
|
||||
private class DataContextInfo
|
||||
{
|
||||
public List<IconfontInfo> iconListSystem;
|
||||
public List<IconfontInfo> iconListCustom;
|
||||
public IconfontInfo iconInfoSystem;
|
||||
public IconfontInfo iconInfoCustom;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user