How to access to control references in WPF Xaml?
For accessing any element in code behind you will need to set x:Name directive. It tells the XAML parser to add a field representing the named element to the automatically generated portion of the Window class just like Winforms.
In a WPF application, there’s no requirement to name each and every element. You should name only those elements which you want to programatically interact with.
An example:
<TextBlock x:Name="tblText" Text="Stackoverflow rocks."></TextBlock>
EDIT:
I used the following code and I was able to access the list view:
namespace WpfApplicationUnleashed
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
EffectsListView.Width = 10;
}
}
}
<Window x:Class="WpfApplicationUnleashed.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:local="clr-namespace:WpfApplicationUnleashed"
Title="Window1" >
<DockPanel>
<ListView x:Name="EffectsListView"></ListView>
</DockPanel>
</Window>
have you set their x:Name="ControlName"
property in xaml?
Here is more information on x:Name directive.
For example:
<Button x:Name="Button1">Click Me</Button>