I would like to be able to use intellisense in XAML without having a ViewModel as DataContext but having the DataContext of the UserControl.cs
The goal is to be able to see properties under development.
Here is an example for demonstration purposes:
<UserControl x:Class="WpfAppNavigationViewControl.NavigationViewControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfAppNavigationViewControl"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" x:Name="PanelColumn"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- Navigation Panel -->
<StackPanel x:Name="NavigationPanel" Background="LightGray">
<Button Content="Collapse Panel" Click="TogglePanelButton_Click"/>
<ListView x:Name="NavigationList"
ItemsSource="{Binding Path=NavigationItems, RelativeSource={RelativeSource AncestorType=UserControl}}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding Path=LeftIcon}" Width="16" Height="16" Margin="5"/>
<TextBlock Grid.Column="1" Text="{Binding Path=Title}" VerticalAlignment="Center" Margin="5"/>
<Image Grid.Column="2" Source="{Binding Path=RightIcon}" Width="16" Height="16" Margin="5"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
<!-- Main Content -->
<Grid Grid.Column="1">
<TextBlock Text="Main Content Area" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="24"/>
</Grid>
</Grid>
</UserControl>
Code Behind
using System.Windows;
using System.Windows.Controls;
namespace WpfAppNavigationViewControl
{
/// <summary>
/// Interaction logic for NavigationViewControl.xaml
/// </summary>
public partial class NavigationViewControl : UserControl
{
private bool isPanelCollapsed = false;
private readonly GridLength expandedWidth = new GridLength(200);
private readonly GridLength collapsedWidth = new GridLength(50);
public NavigationViewControl()
{
InitializeComponent();
DataContext = this;
}
public static readonly DependencyProperty NavigationItemsProperty = DependencyProperty.Register("NavigationItems",
typeof(IEnumerable<NavigationItem>), typeof(NavigationViewControl), new PropertyMetadata(null));
public IEnumerable<NavigationItem> NavigationItems
{
get { return (IEnumerable<NavigationItem>)GetValue(NavigationItemsProperty); }
set { SetValue(NavigationItemsProperty, value); }
}
private void TogglePanelButton_Click(object sender, RoutedEventArgs e)
{
if (isPanelCollapsed)
{
PanelColumn.Width = expandedWidth;
(sender as Button).Content = "Collapse Panel";
}
else
{
PanelColumn.Width = collapsedWidth;
(sender as Button).Content = "Expand Panel";
}
isPanelCollapsed = !isPanelCollapsed;
}
}
}
I would like to be able to view the NavigationItems list
I expect the result like this example but it has nothing to do with the example above