MenuItem Highlight Stays After MouseLeave - wpf

I have this menuitem inside of a combobox:
<MenuItem Name="CurrencySelectMenuItem" Header="Currency" Width="Auto"
Background="Black" Foreground="White" BorderThickness="0" Margin="0"
BorderBrush="Black" VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
When I highlight the item, it does what I want: it pops up the way it should to display it's children, and highlights to show that it's focused. However, when the mouse leaves, the menuitem stays highlighted, even after clicking some other part of my application.
I tried setting the IsFocused property but it is read only.
Can someone point me in the right direction please?
EDIT (code added):
<Grid>
<ComboBox Name="SettingsCmbx" Text="Options" Foreground="White" VerticalContentAlignment="Center" HorizontalContentAlignment="Stretch" Width="80" Style="{StaticResource blackGradientComboBox}" Margin="3">
<ComboBox.ItemsSource>
<CompositeCollection>
<!--<ComboBoxItem Name="Options" IsEnabled="False" Style="{StaticResource blackComboBoxItem}">Options</ComboBoxItem>-->
<ComboBoxItem Style="{StaticResource blackComboBoxItem}">Guidelines</ComboBoxItem>
<ComboBoxItem Style="{StaticResource blackComboBoxItem}">Copy Investigation</ComboBoxItem>
<MenuItem Name="CurrencySelectMenuItem" Header="Currency" Background="Black" Foreground="White" BorderThickness="0" Margin="0" BorderBrush="Black" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<MenuItem Name="DollarSelectMenuItem" Header="_$ - Dollar" Background="Black" Foreground="White"></MenuItem>
<MenuItem Name="PoundSelectMenuItem" Header="_£ - Pound" Background="Black" Foreground="White"></MenuItem>
</MenuItem>
<ComboBoxItem Style="{StaticResource blackComboBoxItem}">About</ComboBoxItem>
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
<TextBlock Name="OptionsTxtBlk" Text="Options" IsHitTestVisible="False" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
Here's the image:

Related

WPF using StackPanel within a a menu

I have a wpf application where I am using a side menu. In one section of the menu I have a Header menuitem and two sub menuitems. I change the background on the two sub menuitems to show a difference. There is a slight gap between the two sub menuitems with a different color. I want the background of both sub menuites to be the same with not gap in between. Here is my menu code:
<MenuItem x:Name="miReplaceLF" Header="Replace Line Feeds" Height="24" VerticalAlignment="Center"
ToolTip="Replace all line feeds in choosen fields with the replacement character." />
<MenuItem x:Name="smiDBFile" Header="DataBase Table"
Click="MenuItem_Click_RLFDBDatabase" Background="#FFBEEBF7"
Margin="15,0,0,0"
ToolTip="Replace line feeds on fields in a database table." />
<MenuItem x:Name="smiExcelTextFile" Header="Excel or Text File" Height="24"
VerticalAlignment="Top" Click="MenuItem_Click_RLFExcelText" Background="#FFBEEBF7"
Margin="15,0,0,0"
ToolTip="Choose a Excel/Text File." />
I tried putting the two sub menuitems within a stackpanel. This gives me the ability to have the uniform background I want but the sub menuitems are shifted to the right way too much. I just want a small indent on the two sub menuitem. I can't find a way to get the menuitems alligned to the left. Here is the code with the stackpanel.
<MenuItem x:Name="miReplaceLF" Header="Replace Line Feeds" Height="24" VerticalAlignment="Center"
ToolTip="Replace all line feeds in choosen fields with the replacement character." />
<StackPanel Background="#FFBEEBF7">
<MenuItem x:Name="smiDBFile" Header="DataBase Table"
Click="MenuItem_Click_RLFDBDatabase" Background="#FFBEEBF7"
Margin="0,0,0,0"
ToolTip="Replace line feeds on fields in a database table." />
<MenuItem x:Name="smiExcelTextFile" Header="Excel or Text File" Height="24"
Click="MenuItem_Click_RLFExcelText" Background="#FFBEEBF7"
Margin="0,0,0,0"
ToolTip="Choose a Excel/Text File." />
</StackPanel>
Here is the full XAML code, this has been changed to use the suggestions by Ed Plunkett
<Window x:Class="TextUtilities.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:TextUtilities"
mc:Ignorable="d"
Title="Text Utilites" x:Name="TextUtils" Height="420" Width="900" Left="100" Top="30"
ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" Background="#FFDBF4FB">
<Window.Resources>
<Style
TargetType="MenuItem"
BasedOn="{StaticResource {x:Type MenuItem}}"
x:Key="RLFItem">
<Setter Property="Margin" Value="15,0,0,0" />
<Setter Property="Background" Value="#FFBEEBF7" />
</Style>
</Window.Resources>
<Grid>
<Menu HorizontalAlignment="Left" Width="150" Margin="0,2,0,0" FontFamily="Arial" FontSize="14.667"
BorderThickness="0,2,2,0" BorderBrush="#FFE0E0E0" Background="#FFDBF4FB">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel x:Name="spItemsPanel" Background="#FFDBF4FB" />
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem x:Name="miReplaceLF" Header="Replace Line Feeds" Height="24" VerticalAlignment="Center"
ToolTip="Replace all line feeds in choosen fields with the replacement character."/>
<MenuItem x:Name="smiDBFile" Header="DataBase Table" Height="24"
Style="{StaticResource RLFItem}" Click="MenuItem_Click_RLFDBDatabase"
ToolTip="Replace line feeds on fields in a database table." />
<MenuItem x:Name="smiExcelTextFile" Header="Excel or Text File" Height="24"
Style="{StaticResource RLFItem}" Click="MenuItem_Click_RLFExcelText"
ToolTip="Choose a Excel/Text File." />
<MenuItem x:Name="miCreateLF" Header="Create Line Feeds" Height="24" VerticalAlignment="Center" ToolTip="Replace all the replacement characters with line feeds." />
<MenuItem x:Name="miViewTextField" Header="View Text Field" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_ViewTextField" ToolTip="Display the contents of a text field. Allows you to see how the data will be displayed in the UI." />
<MenuItem x:Name="miViewSPTEXT" Header="View SPTEXT" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_ViewSPTEXT" ToolTip="Display field sptd_text from table sptextdt. Allows you to see how the data will be displayed in the UI." />
<MenuItem x:Name="miSPlitLargeFile" Header="Split Large File" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_SLF" ToolTip="Split large files, over 60MB into smaller files." />
<MenuItem x:Name="miHowTo" Header="How To" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_HowTo" ToolTip="Instructions on how to use the SPText Utilities." />
<Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" />
<MenuItem Header="Close" Height="24" VerticalAlignment="Center" Click="MenuItem_Click_Close" />
</Menu>
<Grid x:Name="grdRLFDatabase" Visibility="Visible" Height="350" Margin="155,0,0,0" VerticalAlignment="Top">
<TextBox x:Name="txtRLFDBTitle" IsReadOnly="True" TextWrapping="Wrap"
Text="Process to clean a database table and create a pipe delimited text file. You may type in a server instance or select one from the list. Once a server is choosen please cliack the 'Load DB Info' button."
HorizontalAlignment="Left" Height="62" Margin="10,4,0,0" VerticalAlignment="Top" Width="659" FontFamily="Arial"
FontSize="16" Padding="5,1,1,1" Background="#FFDBF4FB" BorderBrush="Gray" BorderThickness="1"/>
<Label x:Name="lblRLFDBInstance" Content="Enter Database Instance:" HorizontalAlignment="Left" Height="28" Margin="5,87,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<ComboBox x:Name="cbxRLFDBInstances" x:FieldModifier="public" HorizontalAlignment="Left" Height="28" Margin="189,87,0,0" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" IsEditable="True"/>
<Button x:Name="btnRLFDBLoadDBInfo" Content="Load DB Info" HorizontalAlignment="Left" Height="26" Margin="475,89,0,0" VerticalAlignment="Top" Width="101" FontFamily="Arial" FontSize="14.667" Click="btnRLFDBLoadDBInfo_Click" Background="#FFEEFFFF" ToolTip="Click here after choosing or typing in the datbase instance. This will populate the database list."/>
<Label x:Name="lblRLFDBName" Content="Choose Database:" HorizontalAlignment="Left" Height="28" Margin="5,131,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<ComboBox x:Name="cbxRLFDBName" x:FieldModifier="public" HorizontalAlignment="Left" Height="28" Margin="189,132,0,0" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" IsEditable="True" SelectionChanged="cbxRLFDBName_SelectionChanged" ToolTip="Once a database is choosen the table list will automatically be populated."/>
<Label x:Name="lblRLFDBTableName" Content="Choose Table:" HorizontalAlignment="Left" Height="28" Margin="5,176,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<ComboBox x:Name="cbxRLFDBTableName" x:FieldModifier="public" HorizontalAlignment="Left" Height="28" Margin="189,177,0,0" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" IsEditable="True" />
<Label x:Name="lblRLFDBOutputName" Content="Choose Output Folder:" HorizontalAlignment="Left" Height="28" Margin="5,233,0,0" VerticalAlignment="Top" Width="175" FontFamily="Arial" FontSize="14.667"/>
<TextBox x:Name="txtRLFDBOutputFolder" x:FieldModifier="public" IsReadOnly="True" HorizontalAlignment="Left" Height="50" Margin="189,222,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="250" FontFamily="Arial" FontSize="14.667" />
<Button x:Name="btnRLFDBBrowseFolder" Content="Browse..." x:FieldModifier="public" HorizontalAlignment="Left" Height="26" Margin="475,235,0,0" VerticalAlignment="Top" Width="74" FontFamily="Arial" FontSize="14.667" Background="#FFEEFFFF" Click="btnRLFDBBrowseFolder_Click" ToolTip="Choose the folder where the text file will be saved to. The file will be named the same as a the table with '_duc' appended to the end."/>
<Button x:Name="btnRLFDBSubmit" Content="Submit" x:FieldModifier="public" HorizontalAlignment="Left" Height="26" Margin="261,300,0,0" VerticalAlignment="Top" Width="74" FontFamily="Arial" FontSize="14.667" Background="#FFEEFFFF" Click="btnRLFDBSubmit_Click"/>
</Grid>
<Grid x:Name="grdRLFExcelText" Visibility="Hidden" Height="320" Width="750" Margin="150, 0, 0 0" VerticalAlignment="Top">
<Label x:Name="lblRLFFileInfo" Content="Process to replace Line Feeds in text fields." HorizontalAlignment="Left" Margin="3,15,0,0" VerticalAlignment="Top" Width="583" Height="30" FontFamily="Arial" FontSize="18.667" FontWeight="Bold"/>
<Label x:Name="lblRLFFileName" Content="Enter the filename:" HorizontalAlignment="Left" Margin="3,79,0,0" VerticalAlignment="Top" Width="162" Height="30" FontFamily="Arial" FontSize="16"/>
<TextBox x:Name="txtRLFFileName" HorizontalAlignment="Left" Height="50" Margin="186,70,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="400" VerticalContentAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold" Background="#FFDBF4FB" TextChanged="txtRLFFileName_TextChanged" />
<Button x:Name="btnRLFFileBrowse" Content="Browse..." HorizontalAlignment="Left" Margin="630,84,0,0" VerticalAlignment="Top" Width="89" FontFamily="Arial" FontSize="16" Background="#FFDBF4FB" Click="btnRLFFileBrowse_Click"/>
<Label x:Name="lblRLFOutputFolder" Content="Choose output folder:" HorizontalAlignment="Left" Margin="3,149,0,0" VerticalAlignment="Top" Width="180" Height="30" FontFamily="Arial" FontSize="16"/>
<TextBox x:Name="txtRLFOutputFolder" HorizontalAlignment="Left" Height="50" Margin="186,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="400" VerticalContentAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold" Background="#FFDBF4FB" TextChanged="txtRLFOutputFolder_TextChanged"/>
<Button x:Name="btnRLFFolderBrowse" Content="Browse..." HorizontalAlignment="Left" Margin="630,154,0,0" VerticalAlignment="Top" Width="89" FontFamily="Arial" FontSize="16" Background="#FFDBF4FB" Click="btnRLFFolderBrowse_Click"/>
<Label x:Name="lblRLFFieldDelim" Content="Field Delimiter:" HorizontalAlignment="Left" Margin="190,202,0,0" VerticalAlignment="Top" Width="118" Height="30" FontFamily="Arial" FontSize="16"/>
<TextBox x:Name="txtRLFFieldDelim" HorizontalAlignment="Left" Height="22" Margin="312,206,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="18" VerticalContentAlignment="Center" FontFamily="Arial" FontSize="16" FontWeight="Bold" Background="#FFDBF4FB" TextChanged="txtRLFFileName_TextChanged" MaxLength="2" HorizontalContentAlignment="Center" />
<CheckBox x:Name="chbxRLFHeaders" Content="Has Header Row" HorizontalAlignment="Left" Height="17" Margin="430,208,0,0" VerticalAlignment="Top" Width="149" FontFamily="Arial" FontSize="16" Checked="chbxRLFHeaders_Checked" Unchecked="chbxRLFHeaders_Unchecked"/>
<Button x:Name="btnRLFSubmit" Content="Submit" HorizontalAlignment="Left" Margin="319,259,0,0" VerticalAlignment="Top" Width="82" Height="31" Background="#FFDBF4FB" FontFamily="Arial" FontSize="16" Click="btnRLFSubmit_Click"/>
</Grid>
</Grid>
</Window>
You can create a MenuItem style which changes Padding or Margin (your choice; try both) and background color for the menu items you apply it to, and then set it on whichever items you chose:
<Window.Resources>
<Style
TargetType="MenuItem"
BasedOn="{StaticResource {x:Type MenuItem}}"
x:Key="SpecialItem"
>
<Setter Property="Margin" Value="15,0,0,0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="#FFBEEBF7" />
</Style>
</Window.Resources>
...
<MenuItem Header="Foo" />
<MenuItem Header="Bar" Style="{StaticResource SpecialItem}" />
<MenuItem Header="Baz" Style="{StaticResource SpecialItem}" />
The mouse-hover state for those will look a little funny, unfortunately. With the default WPF MenuItem template, or at least the one I'm seeing here, you need to replace the entire control template to change that. We can go there if you need to; let me know.
Update
How to add an image to a Stack Overflow question: Edit the question, then click the "add picture" icon which is highlighted in orange.

Pop up is not opening after Rebinding the DataGrid

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

Remove MenuItem White Space Inside ComboBox

I have a menuitem nestled within a combobox and I've not been able to get rid of the terrible white space to the left and right of it.
The code is:
<Grid>
<ComboBox Name="SettingsCmbx" Text="Options" Foreground="White" VerticalContentAlignment="Center" HorizontalContentAlignment="Stretch" Width="80" Style="{StaticResource blackGradientComboBox}" Margin="3">
<ComboBox.ItemsSource>
<CompositeCollection>
<!--<ComboBoxItem Name="Options" IsEnabled="False" Style="{StaticResource blackComboBoxItem}">Options</ComboBoxItem>-->
<ComboBoxItem Style="{StaticResource blackComboBoxItem}">Guidelines</ComboBoxItem>
<ComboBoxItem Style="{StaticResource blackComboBoxItem}">Copy Investigation</ComboBoxItem>
<MenuItem Name="CurrencySelectMenuItem" Header="Currency" Background="Black" Foreground="White" BorderThickness="0" Margin="0" BorderBrush="Black" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<MenuItem Name="DollarSelectMenuItem" Tag="36" Header="$ - Dollar" Background="Black" Foreground="White"></MenuItem>
<MenuItem Name="PoundSelectMenuItem" Tag="163" Header="£ - Pound" Background="Black" Foreground="White"></MenuItem>
</MenuItem>
<ComboBoxItem Style="{StaticResource blackComboBoxItem}">About</ComboBoxItem>
</CompositeCollection>
</ComboBox.ItemsSource>
</ComboBox>
<TextBlock Name="OptionsTxtBlk" Text="Options" IsHitTestVisible="False" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
It looks like this:
I resolved this by adding negative margins on either side. Margin = "-5,0,-5,0"

I unable to get child control from ListBox control in WPF using MVVM

I am in serious trouble. I have listbox control in which i have many combo box. whenever select the value in combo box, i have to make other controls as hidden. i am using MVVM pattren. i am unable to get the child controls from ListBox control but i can get the ListBox control in viewmodel. How can i get these controls in viewmodel? Is it possible? I am using framework 4.0. i have shown the code below which write in view.
<ListBox x:Name="lstItems" MaxHeight="300" FontSize="11" Margin="12,0,20,38" ItemsSource="{Binding Source={StaticResource listedView}, Path=myItemsSource, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
<ListBox.ItemTemplate >
<DataTemplate>
<Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
<StackPanel Orientation="Horizontal">
<Label Content="Show rules where:" Name="lblshowrules"></Label>
<ComboBox x:Name="cboShowRuleWhere" Height="20" Width="200" ItemsSource="{Binding Source={StaticResource listedView}, Path=FilterRules}" DisplayMemberPath="RuleName" SelectedValuePath="RuleId" SelectedValue="{Binding Source={StaticResource listedView}, Path=SelectedRuleName, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" ></ComboBox>
<Grid Height="29" HorizontalAlignment="Left" Name="grid1" VerticalAlignment="Top" Width="496" Grid.Row="1" Margin="0,0,0,0">
<ComboBox Height="21" HorizontalAlignment="Left" Margin="6,4,0,0" x:Name="cboRuleCondtion" VerticalAlignment="Top" Width="212" />
<TextBox Height="20" HorizontalAlignment="Left" Margin="242,3,0,0" x:Name="txtValue" VerticalAlignment="Top" Width="245" Visibility="Hidden"/>
<ComboBox Height="21" HorizontalAlignment="Left" Margin="224,3,0,0" x:Name="cboValue" VerticalAlignment="Top" Width="205" Visibility="Hidden" />
<DatePicker Height="28" HorizontalAlignment="Left" Margin="242,-3,0,0" x:Name="dtpFromDate" VerticalAlignment="Top" Width="98" Visibility="Hidden" />
<DatePicker Height="31" HorizontalAlignment="Left" Margin="346,-3,0,0" x:Name="dtpToDate" VerticalAlignment="Top" Width="98" Visibility="Hidden"/>
</Grid>
<Button Name="cmdAddLevel" Padding="0" Margin="-1,1,0,-1" Width="75" Command ="{Binding Source={StaticResource listedView}, Path=AddLevelCommand, UpdateSourceTrigger=PropertyChanged}" BorderBrush="White" BorderThickness="1" Height="25" HorizontalContentAlignment="Center">
<StackPanel Orientation="Horizontal">
<Image Height="16" Width="16" HorizontalAlignment="Left" Margin="1,0,0,-1">
</Image>
<TextBlock Text="Add Level" FontWeight="Bold" Height="16" Width="70" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="8,2,0,-1" />
</StackPanel>
</Button>
<Label Name="lblDeleteLevel" Margin="3,0,0,0" Width="75" TabIndex="7" HorizontalAlignment="Left">
<Hyperlink >
<TextBlock Text="Delete Level" />
</Hyperlink>
</Label>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Please help me. once again, i want to know how to get the child control from parent control... Is it possible?
Using the MVVM pattern, you should not be referencing any of the controls directly. Alternatively, you should create a boolean property on your viewmodel that decides if various controls should be visible. Then bind the Visibility property of the controls you want to hide to this property, using a converter.
See this previous Q/A for details on visibility converters: Link

Passing Click Events in Composite WPF/XAML Controls

So, let's say I have a DataTemplate:
<DataTemplate x:Key="ProjectsDataItemTemplate">
<ComboBoxItem x:Name="ProjectComboBox"
Opacity="1" HorizontalAlignment="Stretch"
Foreground="#FF80BBD2"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Background="Transparent"
Style="{DynamicResource ComboBoxItemStyle1}">
<StackPanel>
<Label Content="{Binding Name}" Height="32" VerticalContentAlignment="Top"
FontWeight="Bold" Foreground="#FFFEF9F9" AllowDrop="True" />
<TextBlock Text="{Binding Description}"
Foreground="#FF80BBD2"
Padding="5,0,0,10"
FontStyle="Italic" />
</StackPanel>
</ComboBoxItem>
</DataTemplate>
In this case, the Label and the TextBlock both overlap the clickable area for the ComboBoxItem. How do I ignore and/or pass a click through to the ComboBoxItem when I click one of its child controls?
Just set the IsHitTestVisible property to false for those elements:
<DataTemplate x:Key="ProjectsDataItemTemplate">
<ComboBoxItem x:Name="ProjectComboBox"
Opacity="1"
HorizontalAlignment="Stretch"
Foreground="#FF80BBD2"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Background="Transparent"
Style="{DynamicResource ComboBoxItemStyle1}">
<StackPanel>
<Label IsHitTestVisible="False"
Content="{Binding Name}"
Height="32"
VerticalContentAlignment="Top"
FontWeight="Bold"
Foreground="#FFFEF9F9"
AllowDrop="True" />
<TextBlock IsHitTestVisible="False"
Text="{Binding Description}"
Foreground="#FF80BBD2"
Padding="5,0,0,10"
FontStyle="Italic" />
</StackPanel>
</ComboBoxItem>
</DataTemplate>

Resources