2016-08-30 18 views
-1

私は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> 
+2

設定Xのような

:ResourceDictionaryの上のクラスには意味がありません。これは、ResourceDictionaryがそのクラスから派生していることを意味します。あなたは確かに 'xmlns:altoss =" clr-namespace:AltoSS "のようなXML名前空間宣言をして、' '(悪いクラス名btw)のような辞書のようなコンバーターをインスタンス化します。 。もう一度、ドキュメントの読込みを開始する必要があります。 – Clemens

答えて

1

私はないのp thatsのだと思いますossible:x:Class-Attributeを複数回設定する(多型性を目的とする)。

Converters(より具体的な名前はより良いでしょう)とEventHandelerだけを使用する場合は、両方のクラスの名前空間をRD-Tagで定義する必要があります(xmlns:YourNamespace = clr-namespace:YourProjectと似ています)。 NamespaceName)。

次に、x:Keyを静的リソースとして使用してコンバーターを定義することができます。この

<ResourceDictionary xmlns:my="clr-namespace:AltoSS" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:AltoConverters="AltoSS.NamespaceConverters" 
      xmlns:AltoEventHandlers="AltoSS.NamespaceEventHandlers"> 
      <!--NamespaceConverters and NamespaceEventHandlers from your cs files --> 

<!-- for use as static Resource -->  
<AltoConverters:Converters x:Key="YourConverters" /> 

    <!-- example --> 
    <Style TargetType="TextBlock"> 
     <Setter Property="Text" Value="{Binding ...Path..., Converter={StaticResource YourConverters}" /> 
    </Style> 
</ResourceDictionary> 
関連する問題