확장 WPF 툴킷에서 IntegerUpDown
컨트롤을 사용하고 있으며 Caliburn.Micro 및 PostSharp도 사용하고 있습니다. 내 ViewModel의 속성을 기반으로 컨트롤의 최대 값과 최소값을 설정하려고했습니다.Extended WPF Toolkit과 함께 Calburn.Micro 사용?
작동하려면 최소 또는 최대 값을 얻을 수 있지만 둘 다 사용할 수는 없습니다. 그래서 나는 분명히 마지막 속성 바인딩 만 허용하는 무언가를하고 있습니다. 여기 내 AppBootstrapper
클래스 : 위의 예에서
using Caliburn.Micro;
using System.Windows;
using Xceed.Wpf.Toolkit;
namespace Test {
public class AppBootstrapper : Bootstrapper<MainViewModel>{
static AppBootstrapper() {
var baseBindProperties = ViewModelBinder.BindProperties;
ConventionManager.AddElementConvention<FrameworkElement>(IntegerUpDown.MinimumProperty, "Minimum", "ValueChanged");
ViewModelBinder.BindProperties =
(frameWorkElements, viewModels) => {
foreach (var frameworkElement in frameWorkElements) {
var propertyName = frameworkElement.Name + "Minimum";
var property = viewModels
.GetPropertyCaseInsensitive(propertyName);
if (property != null) {
var convention = ConventionManager
.GetElementConvention(typeof(FrameworkElement));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModels,
propertyName,
property,
frameworkElement,
convention,
convention.GetBindableProperty(frameworkElement));
}
}
return baseBindProperties(frameWorkElements, viewModels);
};
ConventionManager.AddElementConvention<FrameworkElement>(IntegerUpDown.MaximumProperty, "Maximum", "ValueChanged");
ViewModelBinder.BindProperties =
(frameWorkElements, viewModels) => {
foreach (var frameworkElement in frameWorkElements) {
var propertyName = frameworkElement.Name + "Maximum";
var property = viewModels
.GetPropertyCaseInsensitive(propertyName);
if (property != null) {
var convention = ConventionManager
.GetElementConvention(typeof(FrameworkElement));
ConventionManager.SetBindingWithoutBindingOverwrite(
viewModels,
propertyName,
property,
frameworkElement,
convention,
convention.GetBindableProperty(frameworkElement));
}
}
return baseBindProperties(frameWorkElements, viewModels);
};
}
}
}
, 최대 값은 최소값을 설정할 수 있지만되지 않습니다. 최소 바인딩이 마지막으로 설정되도록 최소로 바꾸지 만 최소는 작동하지만 최대는 작동하지 않습니다. 여기서 내가 뭘 잘못하고 있니?
<Window x:Class="Test.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBox Name="Text"/>
<xctk:IntegerUpDown Name="Number"/>
<Button Name="Click" Height="25" Content="Test"/>
</StackPanel>
</Window>
과 MainViewModel.cs :
완성도를 위해서이를 실행하려는 경우, 여기에 MainView.xaml입니다 내가 알아 낸 무엇
using Caliburn.Micro;
using PostSharp.Patterns.Model;
using System;
namespace Test {
[NotifyPropertyChanged]
public class MainViewModel : Screen {
public string Text { get; set; }
public int Number { get; set; }
public int NumberMaximum { get; set; }
public int NumberMinimum { get; set; }
public MainViewModel()
: base() {
this.NumberMinimum = 50;
this.NumberMaximum = 100;
this.Number = 75;
}
public void Click() {
Console.WriteLine("Text: '"+this.Text+"'");
Console.WriteLine("Number: '"+this.Number+"'");
}
protected void OnPropertyChanged(string propertyName) {
NotifyOfPropertyChange(propertyName);
}
}
}