I'm new to wpf, but even so I thought this is a trivial problem. So i have а listbox with 4 columns: file names, textbox, checkbox and a button. The buttons are working fine, but for some reason i can't use the textboxes - can't click them or write inside them.
Here is my xaml:
<ListBox Name="lbDocxFiles" HorizontalContentAlignment="Stretch" Margin="10,0" Grid.ColumnSpan="2" Grid.Row="2" SelectionChanged="lbDocxFiles_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<CheckBox x:Name="checkBox" Grid.Column="3" Content="" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBox x:Name="tbNodeID" IsReadOnly="False" AcceptsReturn="True" IsEnabled="True" Focusable="True" TextWrapping="Wrap" HorizontalAlignment="Right" Height="25" Width="90" Text="" VerticalAlignment="Center" Grid.ColumnSpan="1">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="IsReadOnly" Value="False" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Button Grid.Column="2" Width="70" Height="25" Content="UPLOAD" Click="btnUpload_Click" Background="#FF70ECD5" BorderThickness="0" Foreground="White" />
<TextBlock Grid.Column="0" Text="{Binding fileTitle}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
I guess i'm doing something wrong, but can't find out why the texboxes are not editable. Any help will be appreciated!
Thanks in advance!
Refer the below code. It should work. There some UI layout issue.
<ListBox x:Name="lbDocxFiles" HorizontalContentAlignment="Stretch" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="90" />
<ColumnDefinition Width="70" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<CheckBox x:Name="checkBox" Grid.Column="3" Content="Tets" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBox x:Name="tbNodeID" IsReadOnly="False" AcceptsReturn="True"
IsEnabled="True" Focusable="True" TextWrapping="Wrap" HorizontalAlignment="Right"
Height="25" Width="90" Text="" VerticalAlignment="Center" Grid.Column="1">
<TextBox.Style>
<Style TargetType="{x:Type TextBox}">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter Property="IsReadOnly" Value="False" />
</Trigger>
<Trigger Property="IsFocused" Value="False">
<Setter Property="IsReadOnly" Value="True" />
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
<Button Grid.Column="2" Width="70" Height="25" Content="UPLOAD"
Background="#FF70ECD5" BorderThickness="0" Foreground="White" />
<TextBlock Grid.Column="0" Text="{Binding MyProperty}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ObservableCollection<MyModel> lst = new ObservableCollection<MyModel>();
lst.Add(new MyModel() { MyProperty = "Hi" });
lbDocxFiles.ItemsSource = lst;
}
}
class MyModel
{
private string myVar;
public string MyProperty
{
get { return myVar; }
set { myVar = value; }
}
}
So i found a solution here that works. We set the FocusManager.FocusedElement property in style trigger:
<Window.Resources>
<Style x:Key="{x:Type ListBoxItem}" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<StackPanel FocusManager.FocusedElement="{Binding ElementName=MyTextBox}" Orientation="Horizontal">
<Grid Margin="0,2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding fileTitle}" Grid.Column="0" />
<TextBox Name="tbNodeID" Text="{Binding Details}" Height="25" Width="90" HorizontalAlignment="Right" Grid.Column="2" />
<Button Grid.Column="1" Width="70" Height="25" HorizontalAlignment="Right" Content="UPLOAD" Click="btnUpload_Click" Background="#FF70ECD5" BorderThickness="0" Foreground="White" />
<CheckBox x:Name="checkBox" Grid.Column="3" Content="" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</Grid>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="Selector.IsSelected" Value="True">
<Setter TargetName="tbNodeID" Property="FocusManager.FocusedElement" Value="{Binding ElementName=tbNodeID}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter TargetName="tbNodeID" Property="FocusManager.FocusedElement" Value="{Binding ElementName=tbNodeID}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<ListBox Name="myLB" SelectedIndex="{Binding MySelectedIndex}">
</ListBox> </Grid>
This not only makes my textbox editable, but also focus it when item from the listbox is clicked.
Related
<telerik:RadListBox
Grid.Row="2"
Width="638"
Height="500"
HorizontalAlignment="Left"
VerticalAlignment="Top"
AllowDrop="True"
BorderThickness="0"
ItemsSource="{Binding DataSource}">
<telerik:RadListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="TileGrid" MouseEnter="TileGrid_MouseEnter">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="90" />
<ColumnDefinition Width="370" />
</Grid.ColumnDefinitions>
<Image
x:Name="DragHandle"
Width="6"
Height="14"
Visibility="Hidden" />
<telerik:RadToggleButton
Grid.Column="1"
Margin="12,4,0,4"
HorizontalAlignment="Left"
VerticalAlignment="Center"
IsChecked="{Binding TileVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="{Binding AllowEditing}" />
<TextBlock
x:Name="TileNameTextBlock"
Grid.Column="2"
Margin="10,0,0,0"
Style="{StaticResource TextBlockNormal}"
Text="{Binding TileName}"
Visibility="{Binding ShowRenameTextBox, Converter={StaticResource BoolToVisibility}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<TextBlock.ToolTip>
<ToolTip>
<Border
Padding="6"
Background="White"
BorderBrush="#C2C2C2"
BorderThickness="1">
<TextBlock Text="{Binding TileNameToolTip}" />
</Border>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
<Border
Grid.Column="2"
Width="306"
Margin="10,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Background="#FFFFFF"
BorderBrush="#CACACA"
BorderThickness="1"
Visibility="{Binding ShowRenameTextBox, Converter={StaticResource ReverseBoolToVis}}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="260" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<AdornerDecorator
Grid.Column="0"
Width="260"
Height="24">
<TextBox
x:Name="TileNameTextBox"
MaxLength="44"
Style="{StaticResource HiddenTextTextBoxStyle}"
Tag="{Binding RelativeSource={RelativeSource Self}, Path=Text, Mode=OneWay}">
<TextBox.Text>
<Binding
Mode="TwoWay"
Path="TileName"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<DataErrorValidationRule />
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
<TextBox.InputBindings>
<KeyBinding Key="Esc" Command="{Binding CancelRenameTileCommand}" />
<KeyBinding Key="Enter" Command="{Binding RenameTileCheckCommand}" />
</TextBox.InputBindings>
</TextBox>
</AdornerDecorator>
<Button Grid.Column="1" Click="RenameTileButtonClick">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="#FFFFFF" />
<Setter Property="Width" Value="22" />
<Setter Property="Height" Value="22" />
<Setter Property="BorderThickness" Value="0" />
</Style>
</Button.Style>
<Image
Width="16"
Height="14"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Button>
<Button Grid.Column="2" Click="CancelNameButtonClick">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="#FFFFFF" />
<Setter Property="Width" Value="22" />
<Setter Property="Height" Value="22" />
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="0" />
</Style>
</Button.Style>
<Image
Width="16"
Height="14"
HorizontalAlignment="Center"
VerticalAlignment="Center"
/>
</Button>
</Grid>
</Border>
<Button
x:Name="Btn"
Grid.Column="2"
Width="26"
Height="26"
HorizontalAlignment="Right"
Click="Button_Click"
Visibility="Hidden" />
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsMouseOver, RelativeSource={RelativeSource AncestorType=Grid}}" Value="True">
<Setter TargetName="DragHandle" Property="Visibility" Value="Visible" />
<Setter TargetName="TileGrid" Property="Background" Value="#E7F0F8" />
<Setter TargetName="Btn" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</telerik:RadListBox.ItemTemplate>
How do I access TextBox here I want to have the cursor focus on end of the textbox for that I have to have access to the textbox. How can it be done? Should It be done from code behind or from ViewModel?
I have tried TileNameTextBox.CaretIndex = TileNameTextBox.Text.Length;
and TileNameTextBox.Focus();
It is not working as I cannot access TileNameTextBox in code behind directly.
The DataContext set in code behind is like
DataContext = new ViewModel();
I have a part of code that makes it so every listbox in my application shows a message when empty.
<Style TargetType="ListBox" BasedOn="{StaticResource {x:Type ListBox}}">
<Style.Triggers>
<Trigger Property="HasItems" Value="False">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<TextBlock FontSize="20" Foreground="{DynamicResource ValidationErrorBrush}"
TextAlignment="Center" Text="Geen data beschikbaar" Width="Auto" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
When I run the application with it enabled (uncommended) the empty listbox indeed display the message.
But when they are filled the item template is wider than it should be.
This is an example where I use a listbox:
<ListBox x:Name="DataGridTraffic"
Grid.Row="1"
SnapsToDevicePixels="True"
ItemsSource="{Binding Path=TrafficJams}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedIndex="-1"
ItemTemplate="{DynamicResource TrafficJamDataTemplateShort}"
AlternationCount="2"
BorderThickness="0"
HorizontalContentAlignment="Stretch"
ItemContainerStyle="{DynamicResource MainListBoxStyle}" />
Does anyone have a clue on what is going on?
Edit:
The first image shows how it is when I enable the trigger.
The second shows the way it is supposed to be.
Edit:
Here is some more as asked for.
This is the Datatemplate for the same thing as the pictures.
<DataTemplate x:Key="BusDeparturesDataTemplateShort" DataType="{x:Type model:BusDeparture}">
<Grid>
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Setter Property="Background" Value="{DynamicResource ValidationErrorLighterBrush}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=DelayText}" Value="">
<Setter Property="Background" Value="Transparent" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Grid Margin="4,8,4,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock TextAlignment="Center"
FontWeight="Bold"
FontSize="32"
Text="{Binding Path=DeparturePlatform}"
Grid.Column="0" Margin="0,0,5,0"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=PlatformChanged}" Value="True">
<Setter Property="Foreground" Value="{DynamicResource ValidationErrorBrush}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=PlatformChanged}" Value="False">
<Setter Property="Foreground" Value="{DynamicResource PrimaryHueMidBrush}" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid>
<StackPanel Orientation="Horizontal"
TextBlock.FontSize="18"
HorizontalAlignment="Left"
VerticalAlignment="Center">
<TextBlock Text="{Binding Path=ServiceNumber}" Width="45" />
<TextBlock Text="{Binding Path=Destination}" />
</StackPanel>
</Grid>
<Grid Grid.Row="1">
<StackPanel Orientation="Horizontal"
TextBlock.FontSize="16"
HorizontalAlignment="Left">
<TextBlock Text="{Binding Path=DepartureTime, StringFormat=HH:mm}" Margin="0,0,4,0" />
<TextBlock Text="{Binding Path=DelayText}" TextAlignment="Right"
Foreground="{DynamicResource ValidationErrorBrush}" />
</StackPanel>
<StackPanel Orientation="Horizontal"
TextBlock.FontSize="16"
HorizontalAlignment="Right">
<TextBlock Text="{Binding Path=Carrier}" TextAlignment="Right"
HorizontalAlignment="Stretch" />
</StackPanel>
</Grid>
</Grid>
</Grid>
</Grid>
</DataTemplate>
And the part where the listbox is in:
<Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<materialDesign:Card Margin="8" Grid.Column="0" Grid.Row="0" VerticalAlignment="Stretch"
materialDesign:ShadowAssist.ShadowDepth="Depth2" x:Name="CardTrain">
...
</materialDesign:Card>
<materialDesign:Card Margin="8" Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch"
materialDesign:ShadowAssist.ShadowDepth="Depth2" x:Name="CardBus">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>
<Border BorderBrush="{DynamicResource MaterialDesignDivider}" BorderThickness="0,0,0,1">
<TextBlock Text="Bustijden" Foreground="{DynamicResource PrimaryHueDarkBrush}"
TextAlignment="Center"
FontSize="36" FontWeight="ExtraBold" />
</Border>
<ListBox x:Name="DataGridBus"
Grid.Row="1"
SnapsToDevicePixels="True"
ItemsSource="{Binding Path=BusDepartures}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedIndex="-1"
ItemTemplate="{DynamicResource BusDeparturesDataTemplateShort}"
AlternationCount="2"
BorderThickness="0"
HorizontalContentAlignment="Stretch"
ItemContainerStyle="{DynamicResource MainListBoxStyle}"
VerticalAlignment="Top" />
</Grid>
</materialDesign:Card>
<materialDesign:Card Margin="8" Grid.Row="0" Grid.Column="2" VerticalAlignment="Stretch"
materialDesign:ShadowAssist.ShadowDepth="Depth2" x:Name="CardTraffic">
...
</materialDesign:Card>
<materialDesign:Card Margin="8" Grid.Row="0" Grid.Column="3" VerticalAlignment="Stretch"
materialDesign:ShadowAssist.ShadowDepth="Depth2" x:Name="CardTwitter">
...
</materialDesign:Card>
<materialDesign:Card Margin="8" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4"
VerticalAlignment="Stretch" materialDesign:ShadowAssist.ShadowDepth="Depth2"
x:Name="CardNews">
...
</materialDesign:Card>
</Grid>
I have code:
<DataTemplate x:Key="SelectedTime">
<Border BorderBrush="DimGray" BorderThickness="4" Margin="-3,-2,-2,-4" Height="35">
<Grid Width="61" Height="31" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="LightGray" >
<Grid.RowDefinitions>
<RowDefinition Height="14"/>
<RowDefinition Height="15"/>
</Grid.RowDefinitions>
<Grid Background="LightBlue" Grid.Row="0" Margin="0,0,0,0">
<TextBlock TextBlock.FontSize="12" HorizontalAlignment="Left" VerticalAlignment="Stretch" TextAlignment="Center" Margin="6,-2,0,0"
Text="{TemplateBinding Tag}"/>
</Grid>
<TextBlock Grid.Row="1" Text="{TemplateBinding Content}" HorizontalAlignment="Left" VerticalAlignment="Stretch" TextAlignment="Center" TextBlock.FontSize="10" Height="12" Margin="16,-2,0,0"/>
</Grid>
</Border>
</DataTemplate>
<Style x:Key="LowerRadioButton"
TargetType="RadioButton"
BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource SelectedTime}" />
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter Property="ContentTemplate" Value="{StaticResource OrdinaryTime}" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid Height="35" x:Name="testGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="15"/>
</Grid.RowDefinitions>
<RadioButton Style="{StaticResource LowerRadioButton}" Content="12.10" Tag="1" Grid.Column="0" Grid.RowSpan="2" />
<RadioButton Style="{StaticResource LowerRadioButton}" Content="13.10" Tag="2" Grid.Column="1" Grid.RowSpan="2" />
<RadioButton Style="{StaticResource LowerRadioButton}" Content="14.10" Tag="3" Grid.Column="2" Grid.RowSpan="2" IsChecked="True" />
</Grid >
I need to bind to tag in my DataTemplate. Tried through construnction "{Binding Path=Tag, RelativeSource={RelativeSource TemplatedParent}}", but it disn't bind, shows the empty text. What am I doing wrong?
You should know that TemplateBinding can be used only in ControlTemplate, not DataTemplate. So you can try something like this as a workaround:
<TextBlock TextBlock.FontSize="12" HorizontalAlignment="Left"
VerticalAlignment="Stretch" TextAlignment="Center" Margin="6,-2,0,0"
Text="{Binding Tag,
RelativeSource={RelativeSource AncestorType=RadioButton}}"/>
I have DataTemplate for my ListView control, which contains few textblocks and a button. I want the button to be visible only when the item is selected.
Here's my DataTemplate code:
<ListView.ItemTemplate>
<DataTemplate>
<Grid Background="AliceBlue">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="90" />
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Left" Margin="10,0,10,0"
VerticalAlignment="Center" FontFamily="Verdana" FontSize="16"
FontWeight="Black" Grid.Column="0" Text="{Binding name}"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Column="1">
<TextBlock FontFamily="Verdana" FontSize="10" Grid.Column="1"
VerticalAlignment="Center" HorizontalAlignment="Center"
Text="Number of Chapters: " />
<TextBlock FontFamily="Verdana" FontSize="12" Grid.Column="1"
VerticalAlignment="Center" HorizontalAlignment="Center"
Text="{Binding chaptersCount}" />
</StackPanel>
<Button HorizontalAlignment="Center" Height="50" Width="80" Content="Read"
Grid.Column="2" Visibility="Hidden" Click="Button_Click_3" Name="ReadButton"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
How can I do that?
You can achieve this with DataTrigger in DataTemplate which will check for IsSelected property of Templated parent:
<ListView.ItemTemplate>
<DataTemplate>
.....
<Button HorizontalAlignment="Center" Height="50"
Width="80" Content="Read"
Grid.Column="2" Visibility="Hidden" Name="ReadButton"/>
</Grid>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected,
RelativeSource={RelativeSource Mode=TemplatedParent}}"
Value="True">
<Setter TargetName="ReadButton" Property="Visibility"
Value="Visible"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListView.ItemTemplate>
You need to slightly change your Button: A quick XAML way would be to add a Trigger on its Visibility to make it hidden when not selected (note: code written here, hopefully there's no typo):
<Button HorizontalAlignment="Center" Height="50" Width="80" Content="Read"
Grid.Column="2" Click="Button_Click_3" Name="ReadButton">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}" Value="False">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
Hi i am working with C# Wpf application.I am continuously getting red squiggly where i am importing my Style for button:
Style="{StaticResource AppButtons}"
It is compiling correctly but continuously giving warning :
The resource "AppButtons" could not resolved.
The full XAML code is :
<UserControl x:Class="AFIC.View.VLANS"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:AFIC.Resources"
xmlns:view="clr-namespace:AFIC.View"
>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
VerticalAlignment="Center"
Content="VLAN NAME"
Foreground="Black"
Opacity="0.8"
/>
<TextBox
Grid.Row="0"
Grid.Column="1"
Margin="0,5,0,0"
Height="25"
Foreground="Black"
Opacity="0.8"
Width="Auto"
Text="{Binding VlanName, UpdateSourceTrigger=PropertyChanged}"
/>
<Label
Grid.Row="1"
Grid.Column="0"
VerticalAlignment="Center"
Content="VLAN ID"
Foreground="Black"
Opacity="0.8"
/>
<TextBox
Grid.Row="1"
Grid.Column="1"
Margin="0,5,0,0"
Height="25"
Foreground="Black"
Opacity="0.8"
Width="Auto"
Text="{Binding VlanID, UpdateSourceTrigger=PropertyChanged}"
/>
<Label
Grid.Row="2"
Grid.Column="0"
VerticalAlignment="Center"
Content="IP FOR VLAN"
Foreground="Black"
Opacity="0.8"
/>
<Grid
Grid.Column="1"
Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox
Grid.Row="2"
Grid.Column="0"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP1, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="1"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP2, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="2"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP3, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="3"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanIP4, UpdateSourceTrigger=PropertyChanged}"
/>
</Grid>
<Label
Grid.Row="3"
Grid.Column="0"
VerticalAlignment="Center"
Content="DEFAULT ROUTE"
Foreground="Black"
Opacity="0.8"
/>
<Grid
Grid.Row="3"
Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<TextBox
Grid.Row="2"
Grid.Column="0"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute1, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="1"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute2, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="2"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute3, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox
Grid.Row="2"
Grid.Column="3"
Margin="5"
VerticalAlignment="Center"
MaxLength="3"
Width="30"
Foreground="Black"
Opacity="0.8"
Text="{Binding VlanDefaultRoute4, UpdateSourceTrigger=PropertyChanged}"
/>
</Grid>
<Button Grid.Column="3"
Grid.Row="0"
Content="Add VLAN"
Margin="10,5,0,0"
Style="{StaticResource AppButtons}"
/>
<Button Grid.Column="3"
Grid.Row="2"
Content="Remove VLAN"
Margin="10,5,0,0"
Style="{StaticResource AppButtons}"
Width="100"/>
<DataGrid Grid.Row="4"
Grid.ColumnSpan="3"
Height="200"
Margin="10,10,0,0">
</DataGrid>
</Grid>
</UserControl>
And here is my Resource dictionary code:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:res="clr-namespace:AFIC.Resources"
xmlns:VM="clr-namespace:AFIC.ViewModel"
>
<Style TargetType="{x:Type Button}" x:Key="AppButtons">
<Setter Property="Height" Value="30"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Opacity" Value="0.5" />
<Setter Property="Foreground" Value="{StaticResource ATTWhite}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="2"
BorderBrush="White"
BorderThickness="0"
Background="{StaticResource ATTBlue}"
>
<ContentPresenter
x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>
<!-- EULA Accept Buuton Style -->
<!-- Style inherits from the AppButtons style set above -->
<Style BasedOn="{StaticResource AppButtons }" TargetType="{x:Type Button}" x:Key="EULAAcceptButton">
<Setter Property="Opacity" Value="0.5" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=EULAAcceptOption}" Value="True">
<Setter Property="Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked, ElementName=EULAAcceptOption}" Value="False">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
<!-- EULA Reject Buuton Style -->
<!-- Style inherits from the AppButtons style set above -->
<Style BasedOn="{StaticResource AppButtons}" TargetType="{x:Type Button}" x:Key="EULARejectButton">
<Setter Property="Opacity" Value="0.5" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, ElementName=EULARejectOption}" Value="True">
<Setter Property="Opacity" Value="1" />
</DataTrigger>
<DataTrigger Binding="{Binding IsChecked, ElementName=EULARejectOption}" Value="False">
<Setter Property="IsEnabled" Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
<!-- Next Button Style. This Style inherits from the Button style seen above. -->
<Style BasedOn="{StaticResource AppButtons }" TargetType="{x:Type Button}" x:Key="NextButtonStyle">
<Setter Property="Opacity" Value="0.5" />
<Setter Property="Content" Value="{x:Static res:Strings.WizardView_Button_Next}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=LastPageConfigure}" Value="True">
<Setter Property="Content" Value="{x:Static res:Strings.WizardView_Button_Configure}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=LastPageFinish}" Value="True">
<Setter Property="Content" Value="{x:Static res:Strings.WizardView_Button_Finish}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
Any suggestion to get me out of this warning would be highly appreciable!?
You should merge the Resource Dictionary (2nd snip) to where you use it (1st snip), follow the following example and you should be good to go:
Add this to your Grid node (could add it in any ancestor node of your Button):
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="Resources/MyResourceDictionary.xaml">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
Some good links to read regarding Resources and Resource Dictionaries:
http://www.codeproject.com/Articles/35346/Using-a-Resource-Dictionary-in-WPF
http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx
Looks like your'e not the only one who encountered such problem, and it sounds like some bug in the VS wpf designer.
However, Expression Blend 4 deals with this problem using a design time resource dictionary which helps resolving such resources.
The resource could not be resolved (VS 2010 RC)