I have a button nested inside two stack panels as shown by this code.
<StackPanel Grid.Row="1" DataContext="{StaticResource AutomaticUISettings}">
<StackPanel Orientation="Horizontal">
<!--Header-->
<Label Content="If Max UI value is met" />
<!--Max UI Value Met Help-->
<Button Content="[?]" Command="{Binding ShowMaxValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Options-->
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to zero" Margin="10,0" />
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMin}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Min UI value" Margin="10,0" />
</StackPanel>
The whole thing is in a Grid in a GroupBox of a UserControl.
The "Max UI Value Met Help" button is not working when clicked. I have similar help buttons to this in a Grid above this StackPanel that work just fine. I tried to copy and paste those in by this and they don't work either.
Why won't this button work?
Update:
I had to switch to a Grid and separate the label & button from the stack of Radio buttons to get it to work, but I want to understand why this didn't work.
The button here is in the same DataContext as the rest of my UserControl. I have multiple help buttons throughout this UserControl and they work, but this one doesn't. It doesn't matter which one I put in there either. I can move the specific button to another location and it works.
I don't like fixing something without understanding why I had to do that.
New Code:
<!--If Max UI is Met-->
<StackPanel Orientation="Horizontal" Grid.Row="1">
<!--Header-->
<Label Content="If Max UI value is met" />
<!--Max UI Value Met Help-->
<Button Content="[?]" Command="{Binding ShowMaxValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Options-->
<StackPanel Grid.Row="2" DataContext="{StaticResource AutomaticUISettings}">
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to zero" Margin="10,0" />
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMin}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Min UI value" Margin="10,0" />
</StackPanel>
Here is what the code looked like before I went to Grids:
<UserControl x:Class="BogusProgram.DummyUI"
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:autoUIsettings="clr-namespace:BogusProgram.Resources"
xmlns:converters ="clr-namespace:BogusProgram.Converters"
xmlns:views="clr-namespace:BogusProgram.Views"
mc:Ignorable="d" >
<!--UserControl Resources-->
<UserControl.Resources>
<!--Automatic UI Settings-->
<autoUIsettings:AutoUISettings x:Key="AutomaticUISettings" />
<!--Enum to Boolean Converter-->
<converters:EnumBooleanConverter x:Key="enumBooleanConverter" />
</UserControl.Resources>
<!--UserControl Command Bindings-->
<UserControl.CommandBindings>
<!--Compare Change of all settings to Last set-->
<CommandBinding Command="{x:Static views:SetupAutoUI.CompareSettings}" Executed="CommandBinding_Executed"/>
<!--Note: Can use individual RoutedCommands per object-->
<!--http://stackoverflow.com/questions/254992/how-can-i-best-handle-wpf-radio-buttons-->
</UserControl.CommandBindings>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--Enable/Disable Automatic UI-->
<CheckBox Content="Enable Automatic UI" IsChecked="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=AutoUIEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" x:Name="AutoUICheckbox" Margin="10,5" />
<!--Automatic UI Settings-->
<GroupBox Header="Automatic UI Settings" Grid.Row="1" Margin="10,5"
IsEnabled="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=AutoUIEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--Set Automatic UI change by value-->
<StackPanel Orientation="Horizontal" Margin="10,5">
<Label Content="Change UI By: " />
<TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=ChangUIby, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="CHuiBy"
TextChanged="CHuiBy_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />
</StackPanel>
<!--Set when to change UI-->
<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="10,5">
<Label Content="Change UI Every:" />
<TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=WaitPeriod, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="CHuiEv"
TextChanged="CHuiEv_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />
<!--Change UI Every Help-->
<Button Content="[?]" Command="{Binding ShowCHuiEvHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Change UI for-->
<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="10,5" IsEnabled="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriodEnabled, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}">
<Label Content="Change UI For: " />
<TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriod, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="RunFor"
TextChanged="RunFor_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />
<!--Change UI For Help-->
<Button Content="[?]" Command="{Binding ShowCHuiForHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Set Max UI value-->
<StackPanel Orientation="Horizontal" Grid.Column="1" Margin="10,5">
<Label Content="Max UI Value:" />
<TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=MaxUI, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="MaxUI"
TextChanged="MaxUI_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />
<!--Max UI Value Help-->
<Button Content="[?]" Command="{Binding ShowMaxValueHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Set Min UI value-->
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1" Margin="10,5">
<Label Content="Min UI Value:" />
<TextBox Text="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=MinUI, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="35" x:Name="MinUI"
TextChanged="MinUI_TextChanged" KeyDown="TextBox_KeyDown" LostFocus="TextBox_LostFocus" />
<!--Min UI Value Help-->
<Button Content="[?]" Command="{Binding ShowMinValueHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Enable/Disable Max Run Period-->
<CheckBox Content="Enable Max Run Period" IsChecked="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriodEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" x:Name="RunPeriodCheckbox" Margin="10" Grid.Column="1" Grid.Row="2"/>
</Grid>
<!--If Max UI is Met-->
<StackPanel Grid.Row="1" DataContext="{StaticResource AutomaticUISettings}">
<StackPanel Orientation="Horizontal">
<!--Header-->
<Label Content="If Max UI value is met" />
<!--Max UI Value Met Help-->
<Button Content="[?]" Command="{Binding ShowMaxValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Options-->
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to zero" Margin="10,0" />
<RadioButton GroupName="MeetMaxUI" IsChecked="{Binding Path=Default.MaxMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMin}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Min UI value" Margin="10,0" />
</StackPanel>
<!--If Min UI is Met-->
<StackPanel Grid.Row="2" DataContext="{StaticResource AutomaticUISettings}">
<StackPanel Orientation="Horizontal">
<!--Header-->
<Label Content="If Min UI value is met" />
<!--Min UI Value Met Help-->
<Button Content="[?]" Command="{Binding ShowMinValueMetHelp}" Margin="5" Foreground="DarkCyan" FontSize="10">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
<!--Options-->
<RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
<RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOver}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to 255" Margin="10,0" />
<RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RollOvertoMax}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to Max UI value" Margin="10,0" />
<RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=RolltoValue}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Roll over to calculated Value" Margin="10,0" />
<RadioButton GroupName="MeetMinUI" IsChecked="{Binding Path=Default.MinMetRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=InvertUI}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Change UI in inverse direction" Margin="10,0" />
</StackPanel>
<!--Max Run Period-->
<StackPanel Grid.Row="3" IsEnabled="{Binding Source={x:Static autoUIsettings:AutoUISettings.Default}, Path=RunPeriodEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
DataContext="{StaticResource AutomaticUISettings}">
<!--Header-->
<Label Content="If Run Period is met" />
<!--Options-->
<RadioButton GroupName="MeetRunPeriod" IsChecked="{Binding Path=Default.RunPeriodRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Stop}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Stop" Margin="10,0" />
<RadioButton GroupName="MeetRunPeriod" IsChecked="{Binding Path=Default.RunPeriodRadio, Mode=TwoWay, Converter={StaticResource enumBooleanConverter}, ConverterParameter=Run}"
Command="{x:Static views:SetupAutoUI.CompareSettings}" Content="Continue to running at last UI" Margin="10,0" />
</StackPanel>
</Grid>
</GroupBox>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="Apply" Command="{Binding ApplyAutoUI}" Padding="5" Margin="10,0" IsEnabled="{Binding AutoUIChanged}" />
<Button Content="Close/Cancel" Command="{Binding CloseAutoUI}" Padding="5" Margin="10,0" />
</StackPanel>
</Grid>
actually you have to understand the diffrence between ContentTemplate and ControlTemplate of a Control( here it is Button ).
ContentTemplate says how your control content should look like with keeping all the events ans properties of the control.
ControlTemplate says how your control got overridden means it loose its all properties ans events so you have ti define them separately.means you have change the control actually.i think that you does not want.
so in place of changing ControlTemplate change its ContentTemplate like this.
<Button>
<Button.ContentTemplate>
<DataTemplate>
<contentpresenter/> // place code how your button should look like
</DataTemplate>
</Button.ContentTemplate>
<Button>
Related
I have to create an ItemsControl like below and a view model with a clickcommand. How can I bind the command to its template?
<ItemsControl Name="connStatusList" HorizontalAlignment="Left" VerticalAlignment="Top" Background="#e0e0e0" Margin="0,0,0,0" MinHeight="325" Width="1700" ItemsSource="{Binding }" >
<ItemsControl.Template>
<ControlTemplate TargetType="{x:Type ItemsControl}">
<Border>
<ItemsPresenter/>
</Border>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Name="wp" HorizontalAlignment="Left" VerticalAlignment="Top" Orientation="Horizontal" Background="#ededed" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel Width="135" Height="160" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="35,1,0,0" >
<WrapPanel Background="{StaticResource connRectangle}" Width="133" Height="128">
<Image Source="{Binding WifiImage}" Width="70" Height="53" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="35,2,0,0"/>
<Image Source="{Binding ConnectedImage}" Width="43" Height="63" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="45,7,0,0" />
</WrapPanel>
<WrapPanel>
<Label Content="{Binding ItemNO}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="35,0,0,0" FontWeight="Bold" FontSize="18"></Label>
<Label Content="{Binding Connected}" Name="lblconnected" Visibility="Collapsed"></Label>
</WrapPanel>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
As you are essentially creating a list of buttons, use a Button in your template to bind the command. I assume your command property is called ClickCommand. You might need to adapt the style of the button e.g. in mouse-over state to fit your application.
<DataTemplate>
<Button Command="{Binding ClickCommand}">
<Button.Content>
<WrapPanel Width="135" Height="160" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="35,1,0,0" >
<WrapPanel Background="{StaticResource connRectangle}" Width="133" Height="128">
<Image Source="{Binding WifiImage}" Width="70" Height="53" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="35,2,0,0"/>
<Image Source="{Binding ConnectedImage}" Width="43" Height="63" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="45,7,0,0" />
</WrapPanel>
<WrapPanel>
<Label Content="{Binding ItemNO}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="35,0,0,0" FontWeight="Bold" FontSize="18"></Label>
<Label Content="{Binding Connected}" Name="lblconnected" Visibility="Collapsed"></Label>
</WrapPanel>
</WrapPanel>
</Button.Content>
</Button>
</DataTemplate>
Alternatively, you could use an event trigger from the Microsoft.Xaml.Behaviors.Wpf NuGet package. With this approach, the ClickCommand is invoked on mouse button up, it does not change any style.
<DataTemplate>
<WrapPanel Width="135" Height="160" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="35,1,0,0">
<b:Interaction.Triggers>
<b:EventTrigger EventName="MouseLeftButtonUp">
<b:InvokeCommandAction Command="{Binding ClickCommand}"/>
</b:EventTrigger>
</b:Interaction.Triggers>
<WrapPanel Background="{StaticResource connRectangle}" Width="133" Height="128">
<Image Source="{Binding WifiImage}" Width="70" Height="53" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="35,2,0,0"/>
<Image Source="{Binding ConnectedImage}" Width="43" Height="63" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="45,7,0,0" />
</WrapPanel>
<WrapPanel>
<Label Content="{Binding ItemNO}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="35,0,0,0" FontWeight="Bold" FontSize="18"></Label>
<Label Content="{Binding Connected}" Name="lblconnected" Visibility="Collapsed"></Label>
</WrapPanel>
</WrapPanel>
</DataTemplate>
I am trying to hide the Textbox inside the list view based on a condition.
<ListView Margin="0" Name="lvAccessPoints" Background="#ff1d1d1d" Grid.Row="1" BorderThickness="0">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<iconPacks:PackIconModern Kind="ConnectionWifi" Foreground="White" Width="30" Height="30"/>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" Padding="10,0" FontSize="15" VerticalAlignment="Center"/>
<TextBox HorizontalAlignment="Left"
Height="23"
Margin="10,10,0,0"
TextWrapping="Wrap"
Text=""
VerticalAlignment="Top"
Width="120"
TextChanged="TextBox_TextChanged"
Visibility="{Binding Name!=SelectedItem.Name ? Hidden : Visible}"/>
<Button Click="Button_Click_2"></Button>
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I am trying like this , and its not seems to be the right way, what i want is when the particular name in the loop matches the selected items name, then only TextBox should show.
What I am doing wrong?
These kind of expressions are not supported in XAML:
Visibility="{Binding Name!=SelectedItem.Name ? Hidden : Visible}"
What you could do is to define a DataTrigger in your DataTemplate that sets the Visibility property of the TextBox to Visible when the parent ListViewItem is selected:
<ListView Margin="0" Name="lvAccessPoints" Background="#ff1d1d1d" Grid.Row="1" BorderThickness="0">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<iconPacks:PackIconModern Kind="ConnectionWifi" Foreground="White" Width="30" Height="30"/>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="White" Padding="10,0" FontSize="15" VerticalAlignment="Center"/>
<TextBox HorizontalAlignment="Left"
x:Name="txt"
Height="23"
Margin="10,10,0,0"
TextWrapping="Wrap"
Text=""
VerticalAlignment="Top"
Width="120"
TextChanged="TextBox_TextChanged"
Visibility="Hidden"/>
<Button Click="Button_Click_2"></Button>
</WrapPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}}" Value="True">
<Setter TargetName="txt" Property="Visibility" Value="Visible" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have 4 IntegerUpDowns from the Xceed toolkit. The problem is that the navigation through Tab button does not work at all. I set TabIndex, TabStop properties, but no effect. Maybe somebody had this problem? Any help will be appreciate! Thanks a lot!
Here is a code:
<GroupBox Margin="20"
HorizontalAlignment="Center"
Header="groupbox header text">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0"
Margin="7"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="text1:" />
<xctk:IntegerUpDown Name="updown1"
Width="50"
Height="25"
Margin="17,0,30,0"
TabIndex="0"
IsTabStop="True"
VerticalAlignment="Center"
Increment="1"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
ValueChanged="Updown1_OnValueChanged"
Value="{Binding Property1,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
<TextBlock VerticalAlignment="Center" Text="text2" />
<xctk:IntegerUpDown Name="updown2"
Width="50"
Height="25"
Margin="43,0,0,0"
VerticalAlignment="Center"
Increment="2"
TabIndex="2"
IsTabStop="True"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
Value="{Binding Property2,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<StackPanel Grid.Row="1"
Margin="7,0,7,7"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="text3:" />
<xctk:IntegerUpDown Name="updown3"
Width="50"
Height="25"
Margin="7,0,30,0"
VerticalAlignment="Center"
Increment="1"
TabIndex="1"
IsTabStop="True"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
ValueChanged="Updown3_OnValueChanged"
Value="{Binding Proeprty3,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
<TextBlock VerticalAlignment="Center" Text="text4:"/>
<xctk:IntegerUpDown Name="updown4"
Width="50"
Height="25"
Margin="7,0,0,0"
TabIndex="3"
VerticalAlignment="Center"
Increment="1"
IsTabStop="True"
PreviewKeyDown="NumericUpDown_OnPreviewKeyDown"
Value="{Binding Property4,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
</Grid>
</GroupBox>
I have started to work on WPF recently. Currently I am facing an issue.
I have a window , inside that i have an user control which Contains DataGrid, Combobox ,Buttons and a Pop Up.
I am binding DataGrid with List of Notes(string) with Delete Buttons.So when we click on that Button, the pop up will open and Pop up has confirmation message with Yes or No button.
When i click the Yes button i am deleting the Note and Rebinding only the DataGrid.And after that when i click on the Delete Button the pop up is not opening.
If I dont Rebind the DataGrid, in that case PopUp is opening but the problem is deleted Note is still there in the DataGrid though that is deleted from the database, which make confusion whether the Note is deleted or not. That is why I am rebinding.
But Rebinding cause the issue of not opening Popup.
Please help me out how can i get this done.
My Pop up looks like this:
<Popup x:Name="Popupdelete"
AllowsTransparency="True"
HorizontalOffset="-10"
VerticalOffset="10"
Placement="Mouse"
StaysOpen="False"
IsOpen="{Binding IsDeletePopUpOpen}">
<Grid x:Name="LayoutRoot" Background="Transparent" Height="105">
<!-- My confirmation message and Yes No button goes Here-->
</Grid>
IsDeletePopUpOpen is set in the ViewModel.
Thanks & Regards,
Joy
Code goes here:
<-- Delete Pop Up-->
<Popup x:Name="Popupdelete"
AllowsTransparency="True"
HorizontalOffset="-10"
VerticalOffset="10"
Placement="Mouse"
StaysOpen="False"
IsOpen="{Binding IsDeletePopUpOpen}">
<Grid x:Name="LayoutRoot" Background="Transparent" Height="105">
<Border BorderBrush="#E2E2E2" BorderThickness="6" Background="White">
<Grid>
<TextBlock TextWrapping="Wrap" Margin="10,10,10,50" Foreground="#454545" FontWeight="SemiBold" HorizontalAlignment="Center" VerticalAlignment="Center" Height="30" Width="Auto" Text="Are you sure you want" />
<TextBlock TextWrapping="Wrap" Margin="50,15,50,25" Foreground="#454545" FontWeight="SemiBold" HorizontalAlignment="Center" VerticalAlignment="Center" Height="30" Width="Auto" Text="to delete?"/>
<Button Content="Yes" Margin="35,50,80,0" Height="40" HorizontalAlignment="Center" VerticalAlignment="Center" Command="{Binding DeleteYesCmd}" CommandParameter="{Binding SelectedItem, ElementName=lstCustomer}" Style="{StaticResource SaveButtonStyle}" />
<TextBlock Text="or" Margin="75,50,60,15" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#919191" FontSize="10" />
<TextBlock Margin="95,48,35,12" HorizontalAlignment="Center" VerticalAlignment="Center" ><Hyperlink Command="{Binding DeleteNoCmd}"><Run Text="No" FontWeight="Bold" FontSize="12"/></Hyperlink></TextBlock>
</Grid>
</Border>
</Grid>
</Popup>
<--List Of Notes with Delete Image Button-->
<Border Background="#F0F0F0" CornerRadius="0" Visibility="{Binding NotesListViewVisibility}">
<ScrollViewer x:Name="scrollMe" CanContentScroll="True" Height="80" >
<Border Background="White" CornerRadius="5,0,0,5">
<Grid Background="White" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="101*"/>
<ColumnDefinition Width="35*"/>
</Grid.ColumnDefinitions>
<ListView x:Name="lstCustomer" BorderBrush="Transparent" BorderThickness="0" ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" RequestBringIntoView="RemoveScrollViewFocus"
ItemsSource="{Binding OutcomeNotesView , Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionMode="Single"
Background="#FFFFFF" ItemContainerStyle="{StaticResource ListviewItemContainerStyle}" Grid.ColumnSpan="2">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UC:NoteStackPanel/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<Border BorderBrush="#E6E6E6" BorderThickness="0,0,0,1"
Width="{Binding ActualWidth, Converter={StaticResource widthconv}, ElementName=lstCustomer}">
<StackPanel x:Name="spNotes" Orientation="Vertical" Margin="0,10,0,10" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Orientation="Horizontal">
<Button x:Name="btnPrimaryOfficer" MouseEnter="SetEmployeePopUpPlacement" Style="{StaticResource AuthButton}"
CommandParameter="{Binding}" Command="{Binding DataContext.OutcomeEmployeePopUp, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}">
<Button.Visibility>
<MultiBinding Converter="{StaticResource ActiveInactiveConv}" ConverterParameter="Hyper">
<Binding Path="EmployeeInfo.ActiveStatusCode"/>
<Binding Path="EmployeeInfo.Id"/>
</MultiBinding>
</Button.Visibility>
<Button.InputBindings>
<MouseBinding Gesture="LeftDoubleClick" CommandParameter="{Binding}"
Command="{Binding DataContext.OutcomeEmployeePopUp, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}"/>
</Button.InputBindings>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource imgUser}" Width="15" Height="15" HorizontalAlignment="Left" />
<TextBlock Text="{Binding EmployeeInfo.Name}" Style="{StaticResource AuthEditProfile}" FontFamily="{StaticResource FontBold}" FontSize="12" Margin="2,0,0,0" />
</StackPanel>
</Button>
<StackPanel Orientation="Horizontal" >
<StackPanel.Visibility>
<MultiBinding Converter="{StaticResource ActiveInactiveConv}" ConverterParameter="Normal">
<Binding Path="EmployeeInfo.ActiveStatusCode"/>
<Binding Path="EmployeeInfo.Id"/>
</MultiBinding>
</StackPanel.Visibility>
<!--Visibility="{Binding PrimaryOfficerActiveStatusCode,Converter={StaticResource ActiveInactiveConv},ConverterParameter=Normal}">-->
<Image Source="{StaticResource imgUserBlack}" Width="15" Height="15" HorizontalAlignment="Left" />
<TextBox Text="{Binding EmployeeInfo.Name}" Style="{StaticResource TextWithoutHyperlink}" Margin="2,0,0,0" />
</StackPanel>
<TextBlock Background="Transparent" Text="on"
FontFamily="{StaticResource FontMedium}" FontSize="12" Foreground="#919191" Margin="4,0,2,0"
VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
<TextBox Text="{Binding AddedDate, StringFormat=\{0:MM/dd/yy\}}" Foreground="#454545" VerticalAlignment="Bottom" MaxLength="{Binding Length}"
HorizontalAlignment="Center" Margin="2,0,0,0" Style="{StaticResource ContentText}"/>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" Visibility="{Binding DataContext.DeleteNoteVisibility, ElementName=OutcomeNotesView}" Orientation="Horizontal">
<StackPanel Orientation="Horizontal" >
<Button x:Name="btnDelete" Width="Auto" MouseEnter="btnDelete_MouseEnter" MouseLeave="btnDelete_MouseLeave"
CommandParameter="{Binding}"
Command="{Binding DataContext.LoadDeletePopUp, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}"
Style="{StaticResource AuthButton}">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource imgdeleteicon}" Style="{StaticResource AuthImage}"/>
</StackPanel>
</Button>
</StackPanel>
</StackPanel>
</Grid>
<StackPanel >
<TextBox Text="{Binding Note}" Foreground="#454545" TextWrapping="Wrap" Height="Auto"
Width="{Binding ActualWidth, Converter={StaticResource widthconv}, ElementName=lstCustomer}"
Style="{StaticResource ContentText}" FontFamily="{StaticResource FontNormal}" FontSize="12" Padding="0"/>
<TextBlock x:Name="txtSavingNoteId" Visibility="Collapsed" Text="{Binding NoteId}" />
</StackPanel>
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Border>
</ScrollViewer>
</Border>
</StackPanel>
public List<ActivityNotesDto> OutcomeNotesView
{
get
{
return outcomeNotesView;
}
set
{
outcomeNotesView = value;
OnPropertyChanged("OutcomeNotesView");
}
}
DeleteActivityNote(deletingNoteDetails);
OutcomeNotesView = GetActivityNotesList();
Please let me know if i am missing something.Since first time when i click button Delete popup is opening and it is deleting but next time when i click on the Delete image it didnt open the pop up.
Thanks & Regards,
Joy
I have a Toolbar whose ItemSource is a collection of toolbarItems which contain the bitmap text and other info for the button and the xaml includes a DataTemplate to bind the data to the button.
Our app now needs to become 508 compliant and when I run the Accessible Event Watcher it is listing all the toolbar button names as "Unknown".
Can someone tell me how to provide a meaningful name to the buttons?
Here's the portion of xaml applying to this issue:
<ToolBar.ItemTemplate>
<DataTemplate DataType="{x:Type src:toolBarItem}">
<DataTemplate.Resources>
<src:toolBarItemConverter x:Key="buttonConverter" />
<src:booleanToVisibilityConverter x:Key="boolToVisibilityConverter" />
<src:toolBarButtonFormatConverter x:Key="toolBarFormatDisplayConverter" />
<src:stringToVisibilityConverter x:Key="stringToVisibilityDisplayConverter" />
</DataTemplate.Resources>
<StackPanel Orientation="Horizontal">
<Border Style="{StaticResource SeparatorStyle}" Visibility="{Binding menuSeparator, Converter={StaticResource boolToVisibilityConverter}}"/>
<Button x:Name="listButton" Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}" VerticalAlignment="Top" HorizontalAlignment="Center" Visibility="{Binding isActiveButton, Converter={StaticResource boolToVisibilityConverter}}" Tag="{Binding}"
ToolTip="{Binding menuTooltip}" IsEnabled="{Binding isEnabled}" >
<UniformGrid VerticalAlignment="Center" HorizontalAlignment="Center" Rows="{Binding menuText,Converter={StaticResource toolBarFormatDisplayConverter}}" >
<!-- button image -->
<Image Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding menuImage, Converter={StaticResource buttonConverter}}"/>
<!-- button name -->
<Viewbox StretchDirection="DownOnly" HorizontalAlignment="Center" VerticalAlignment="Bottom" Visibility="{Binding menuText, Converter={StaticResource stringToVisibilityDisplayConverter}}" >
<TextBlock x:Name="buttonName" FontFamily="Segoe UI" Width="{Binding menuWidth}" FontSize="12" Grid.Row="1" TextAlignment="Center" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding menuText}" Foreground="Black" />
</Viewbox>
</UniformGrid>
<!-- </StackPanel> -->
</Button>
</StackPanel>
</DataTemplate>
</ToolBar.ItemTemplate>
Thanks,
Ron
OK we figured this out. Need to simply bind your names to the AutomationProperties.Name
<Button x:Name="listButton" AutomationProperties.Name="{Binding menuText}"
Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}"
VerticalAlignment="Top" HorizontalAlignment="Center"
Visibility="{Binding isActiveButton,
Converter={StaticResource boolToVisibilityConverter}}"
Tag="{Binding}" ToolTip="{Binding menuTooltip}" IsEnabled="{Binding isEnabled}" >