मैं सिल्वरलाइट 2.0 में एक सरल पहेली पहेली गेम बनाने की कोशिश कर रहा हूं। मैं UserControl-ish घटक पर काम कर रहा हूं जो पहेली में एक वर्ग का प्रतिनिधित्व करता है। मुझे अपने UserControl के गुणों को अपने 'तत्वों के साथ बाध्य करने में परेशानी हो रही है। आखिरकार मैंने (काम किया) इसे काम कर लिया है (कुछ के लिए सहायक हो सकता है - मुझे कुछ घंटे लग गए), लेकिन इसे और अधिक 'सुरुचिपूर्ण' बनाना चाहता था।बाध्यकारी सिल्वरलाइट UserControl अपने गुणों के लिए कस्टम गुण
मैंने कल्पना की है कि इसमें सामग्री और एक लेबल (ऊपरी दाएं कोने में) के लिए एक डिब्बे होना चाहिए जिसमें वैकल्पिक रूप से इसकी संख्या शामिल है। सामग्री नियंत्रण शायद टेक्स्टबॉक्स हो, जबकि लेबल नियंत्रण टेक्स्टब्लॉक हो सकता है।
<UserControl x:Class="XWord.Square"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontSize="30"
Width="100" Height="100">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="Label" Grid.Row="0" Grid.Column="1"
Text="7"/>
<TextBox x:Name="Content" Grid.Row="1" Grid.Column="0"
Text="A"
BorderThickness="0" />
</Grid>
</UserControl>
मैं भी इस तरह स्क्वायर वर्ग में DependencyProperties बना लिया है:: तो मैं इस बुनियादी संरचना के साथ एक UserControl (मानों इस स्तर पर hardcoded कर रहे हैं) बनाया अब
public static readonly DependencyProperty LabelTextProperty;
public static readonly DependencyProperty ContentCharacterProperty;
// ...(static constructor with property registration, .NET properties
// omitted for brevity)...
मैं था लेबल और सामग्री तत्व को दो गुणों में कैसे बांधना है, यह समझना पसंद है। मैं इसे इस तरह करता हूं (कोड-बैक फ़ाइल में):
Label.SetBinding(TextBlock.TextProperty, new Binding { Source = this, Path = new PropertyPath("LabelText"), Mode = BindingMode.OneWay });
Content.SetBinding(TextBox.TextProperty, new Binding { Source = this, Path = new PropertyPath("ContentCharacter"), Mode = BindingMode.TwoWay });
यह एक्सएएमएल में अधिक सुरुचिपूर्ण होगा। क्या किसी को पता है कि यह कैसे किया जाता है?
इस तरह के एक महत्वपूर्ण सवाल अभी तक एक भ्रामक जवाब है। –