>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.