Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best practice for setting DataContext, ItemsSource,etc.
Message
De
24/02/2009 14:18:47
 
 
À
12/02/2009 12:09:18
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01381301
Message ID:
01383875
Vues:
30
>I'm trying to get my brain around whether to set UI control properties for my listviews and textboxes (specifically, DataContext and ItemsSource) in the XAML code or in the C# method code.
>
>For instance, I can set them in the Window constructor:
>
>lvHolePatterns.DataContext = this;
>lvHolePatterns.ItemsSource = HolePatterns;
>
>
>
>or in the XAML:
>
><ListView x:Name="lvHolePatterns" 
>               DataContext="{Binding ElementName=winBoltCircle}"
>               ItemsSource="{Binding Path=HolePatterns}"
>               SelectedItem="{Binding Path=ActivePattern}" IsSynchronizedWithCurrentItem="True"
>               SelectionChanged="lvHolePatterns_SelectionChanged" GotFocus="lvHolePatterns_GotFocus"
>               HorizontalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Visible" Background="Gray">
>
>
>Obviously maintenance and refactoring will be affected by which choice I make, as well as other factors which I probably don't even have a clue about yet.
>
>So, seeking guidance from others here.

Other than the DataContext of the root item (Window/UserControl)

I usually set them in the xaml, it make the xaml easier to read IMHO. But, it's not a hard and fast rule.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform