Commit c0ee5238 by liulongfei

导航配置

WindowHost容器添加渲染目标宽度与高度
parent bce25c66
...@@ -3,6 +3,7 @@ using System.Collections.Generic; ...@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows;
using VIZ.Framework.Core; using VIZ.Framework.Core;
namespace VIZ.Framework.Common namespace VIZ.Framework.Common
...@@ -39,5 +40,29 @@ namespace VIZ.Framework.Common ...@@ -39,5 +40,29 @@ namespace VIZ.Framework.Common
} }
#endregion #endregion
#region ViewModelType -- 视图模型类型
private Type viewModelType;
/// <summary>
/// 视图模型类型
/// </summary>
public Type ViewModelType
{
get { return viewModelType; }
set { viewModelType = value; this.RaisePropertyChanged(nameof(ViewModelType)); }
}
#endregion
/// <summary>
/// 视图
/// </summary>
public WeakReference<object> View { get; set; }
/// <summary>
/// 视图模型
/// </summary>
public WeakReference<object> ViewModel { get; set; }
} }
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<Setter Property="Background" Value="Transparent"></Setter> <Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Visibility" Value="{Binding Path=IsSelected,RelativeSource={RelativeSource Mode=Self},Converter={StaticResource Bool2VisibilityConverter}}"></Setter> <Setter Property="Visibility" Value="{Binding Path=IsSelected,RelativeSource={RelativeSource Mode=Self},Converter={StaticResource Bool2VisibilityConverter}}"></Setter>
<Setter Property="ViewType" Value="{Binding Path=ViewType,Mode=OneWay}"></Setter> <Setter Property="ViewType" Value="{Binding Path=ViewType,Mode=OneWay}"></Setter>
<Setter Property="ViewModelType" Value="{Binding Path=ViewModelType,Mode=OneWay}"></Setter>
<Setter Property="Template"> <Setter Property="Template">
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="local:NavigationItemControl"> <ControlTemplate TargetType="local:NavigationItemControl">
......
...@@ -12,6 +12,7 @@ using System.Windows.Media; ...@@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.Framework.Common namespace VIZ.Framework.Common
{ {
...@@ -68,6 +69,25 @@ namespace VIZ.Framework.Common ...@@ -68,6 +69,25 @@ namespace VIZ.Framework.Common
#endregion #endregion
#region ViewModelType -- 视图模型类型
/// <summary>
/// 视图模型类型
/// </summary>
public Type ViewModelType
{
get { return (Type)GetValue(ViewModelTypeProperty); }
set { SetValue(ViewModelTypeProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for ViewModelType. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty ViewModelTypeProperty =
DependencyProperty.Register("ViewModelType", typeof(Type), typeof(NavigationItemControl), new PropertyMetadata(null));
#endregion
/// <summary> /// <summary>
/// 可见性改变时触发 /// 可见性改变时触发
/// </summary> /// </summary>
...@@ -79,9 +99,33 @@ namespace VIZ.Framework.Common ...@@ -79,9 +99,33 @@ namespace VIZ.Framework.Common
if (this.Content != null && this.Content.GetType() == this.ViewType) if (this.Content != null && this.Content.GetType() == this.ViewType)
return; return;
NavigationConfig config = this.DataContext as NavigationConfig;
if (this.ViewType != null) if (this.ViewType != null)
{ {
this.Content = this.ViewType.Assembly.CreateInstance(this.ViewType.FullName); this.Content = this.ViewType.Assembly.CreateInstance(this.ViewType.FullName);
config.View = new WeakReference<object>(this.Content);
}
if (this.ViewModelType != null)
{
FrameworkElement view = this.Content as FrameworkElement;
if (view != null)
{
object obj = this.ViewModelType.Assembly.CreateInstance(this.ViewModelType.FullName);
config.ViewModel = new WeakReference<object>(obj);
ViewModelBase vm = obj as ViewModelBase;
if (vm == null)
{
view.DataContext = obj;
}
else
{
WPFHelper.BindingViewModel(view, vm);
}
}
} }
} }
} }
......
...@@ -64,6 +64,44 @@ namespace VIZ.Framework.Common ...@@ -64,6 +64,44 @@ namespace VIZ.Framework.Common
#endregion #endregion
#region WindowAdjustWidth -- 窗口计算宽度
/// <summary>
/// 窗口计算宽度
/// </summary>
public int WindowAdjustWidth
{
get { return (int)GetValue(WindowAdjustWidthProperty); }
set { SetValue(WindowAdjustWidthProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for WindowAdjustWidth. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty WindowAdjustWidthProperty =
DependencyProperty.Register("WindowAdjustWidth", typeof(int), typeof(WindowHost), new PropertyMetadata(1920));
#endregion
#region WindowAdjustHeight -- 窗口计算高度
/// <summary>
/// 窗口计算高度
/// </summary>
public int WindowAdjustHeight
{
get { return (int)GetValue(WindowAdjustHeightProperty); }
set { SetValue(WindowAdjustHeightProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for WindowAdjustHeight. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty WindowAdjustHeightProperty =
DependencyProperty.Register("WindowAdjustHeight", typeof(int), typeof(WindowHost), new PropertyMetadata(1080));
#endregion
/// <summary> /// <summary>
/// 容器窗口句柄 /// 容器窗口句柄
/// </summary> /// </summary>
...@@ -147,8 +185,13 @@ namespace VIZ.Framework.Common ...@@ -147,8 +185,13 @@ namespace VIZ.Framework.Common
int width = (int)(sizeInfo.NewSize.Width * (dpi.X / 96d)); int width = (int)(sizeInfo.NewSize.Width * (dpi.X / 96d));
int height = (int)(sizeInfo.NewSize.Height * (dpi.Y / 96d)); int height = (int)(sizeInfo.NewSize.Height * (dpi.Y / 96d));
int render_width = 0;
int render_height = 0;
ImageHelper.AdjustSize(width, height, this.WindowAdjustWidth, this.WindowAdjustHeight, out render_width, out render_height);
// 改变宿主窗口大小 // 改变宿主窗口大小
if (!Win32Helper.MoveWindow(this.PART_ContainerForm.Handle, 0, 0, width, height, false)) if (!Win32Helper.MoveWindow(this.PART_ContainerForm.Handle, (width - render_width) / 2, (height - render_height) / 2, render_width, render_height, false))
{ {
log.Error("resize form error."); log.Error("resize form error.");
} }
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// Bool 转 字符串转化器
/// </summary>
public class Bool2StringConverter : IValueConverter
{
/// <summary>
/// 为True时的返回值
/// </summary>
public string TrueResult { get; set; }
/// <summary>
/// 为False时的返回值
/// </summary>
public string FalseResult { get; set; }
/// <summary>
/// 为Null时的返回值
/// </summary>
public string NullResult { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool?)
{
bool? b = (bool?)value;
if (b == null)
return this.NullResult;
return b.Value ? this.TrueResult : this.FalseResult;
}
else if (value is bool)
{
bool b = (bool)value;
return b ? this.TrueResult : this.FalseResult;
}
else
{
return this.NullResult;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Core\Converter\Bool2BoolConverter.cs" /> <Compile Include="Core\Converter\Bool2BoolConverter.cs" />
<Compile Include="Core\Converter\Bool2StringConverter.cs" />
<Compile Include="Core\Converter\ByteSizeConverter.cs" /> <Compile Include="Core\Converter\ByteSizeConverter.cs" />
<Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" /> <Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" />
<Compile Include="Core\Converter\Color2SolidColorBrushConverter.cs" /> <Compile Include="Core\Converter\Color2SolidColorBrushConverter.cs" />
......
...@@ -17,6 +17,20 @@ namespace VIZ.Framework.Plugin ...@@ -17,6 +17,20 @@ namespace VIZ.Framework.Plugin
// Property // Property
// ================================================================================== // ==================================================================================
#region HasProjectDomain -- 当前是否包含项目领域
private bool hasProjectDomain;
/// <summary>
/// 当前是否包含项目领域
/// </summary>
public bool HasProjectDomain
{
get { return hasProjectDomain; }
set { hasProjectDomain = value; this.RaisePropertyChanged(nameof(HasProjectDomain)); }
}
#endregion
// ================================================================================== // ==================================================================================
// override // override
// ================================================================================== // ==================================================================================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment