私はResourceDictionary
ファイルを持っていますが、私はそれに使用する2つのクラスも持っています。
一方はIValueConverter
であり、他方は対照に関するEventHandlers
である。
クラス名はEventHandlers
であり、属性値はx:Class
です。
また、Converters
を第2のx:Class
と設定する必要があります。
デザイナーがx:Class is set more than one time
というエラーを投げるので、私はそれを行うことができません。
この問題を解決するにはどうすればよいですか?"x:Class"をResourceDictionaryファイルに複数設定することはできますか?
Converters.cs
class Converters : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double pr = (double)value;
AltoProgressBar bar = parameter as AltoProgressBar;
return pr * bar.Width/bar.Maximum;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
EventHandlers.cs
public partial class EventHandlers
{
private void progressBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ProgressBar progressBar = sender as ProgressBar;
var template = progressBar.Template;
//Find the Rectangle in the ControlTemplate
var layer = (Rectangle)(template.FindName("rect", progressBar));
//Calculate the increment amount depending maxValue and Width
double artis = progressBar.Value * progressBar.Width/progressBar.Maximum;
DoubleAnimation anim = new DoubleAnimation(toValue: artis, duration: TimeSpan.FromMilliseconds(100));
layer.BeginAnimation(Rectangle.WidthProperty, anim);
}
}
styles.xaml
<ResourceDictionary xmlns:my="clr-namespace:AltoSS"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AltoSS.Converters"
<!--this doesn't make any sense-->
x:Class="AltoSS.EventHandlers">
<!--All styles in here-->
</ResourceDictionary>
設定Xのような
:ResourceDictionaryの上のクラスには意味がありません。これは、ResourceDictionaryがそのクラスから派生していることを意味します。あなたは確かに 'xmlns:altoss =" clr-namespace:AltoSS "のようなXML名前空間宣言をして、' '(悪いクラス名btw)のような辞書のようなコンバーターをインスタンス化します。 。もう一度、ドキュメントの読込みを開始する必要があります。 –
Clemens