I have a calendar created as follows
<Grid>
<Rectangle Margin="2" Height="25" Name="borderRectangle" VerticalAlignment="Top" Fill="#FFEAEEF9" />
<Button Name="titleButton" Style="{StaticResource ButtonStyle}" Margin="30,1,30,0" FlowDirection="RightToLeft" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" Focusable="True" Click="titleButton_Click" Height="25" VerticalAlignment="Top" FontWeight="Bold" IsTabStop="True" TabIndex="0">خرداد 1397</Button>
<Button Name="previousButton" Style="{StaticResource ButtonStyle}" Height="25" HorizontalAlignment="Right" Margin="0,2,12,0" VerticalAlignment="Top" Width="23" Background="Transparent" BorderThickness="0" Padding="0" FontFamily="Arial" FontSize="14" BorderBrush="Transparent" Click="previousButton_Click" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" IsTabStop="True" TabIndex="0">►</Button>
<Button Name="nextButton" Style="{StaticResource ButtonStyle}" Height="25" HorizontalAlignment="Left" Margin="12,2,0,0" VerticalAlignment="Top" Width="23" Background="Transparent" BorderThickness="0" Padding="0" FontFamily="Arial" FontSize="14" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" BorderBrush="Transparent" Click="nextButton_Click" IsTabStop="True" TabIndex="0">◄</Button>
<UniformGrid Margin="3,26,3,2" Name="monthUniformGrid" Rows="7" Columns="7" FlowDirection="RightToLeft" />
<UniformGrid Margin="3,26,3,2" Name="yearUniformGrid" Columns="3" Rows="4" FlowDirection="RightToLeft" />
<UniformGrid Margin="3,26,3,2" Name="decadeUniformGrid" Columns="3" Rows="4" FlowDirection="RightToLeft" />
</Grid>
And the result is this way
Now I have another calendar control that has beautiful styles I have access to styles, but when I apply it, I get an error
Style="{StaticResource CalendarBaseStyle}"
calendar target type does not match type of element...
and this is my style
<Style x:Key="CalendarBaseStyle" TargetType="{x:Type Calendar}">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="White" />
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
...
As you can see, my calendar is made by Uniform Grid So how can I apply the calendar style to it?
Change the style target type to type of your control, for example:
xmlns:myControls="clr-namespace:MyNamespace.Controls"
....
<Style x:Key="CalendarBaseStyle" TargetType="{x:Type myControls:MyCalendarControl}">
....
Related
i have grid like this:
<Grid Height="100" Width="580" Margin="10,402,10,48">
<TextBlock Text="0-10 V" FontWeight="Bold" Style="{DynamicResource TextBlockStyle}" Width="100" Height="25" Margin="10,10,470,65"/>
<TextBlock Text="Czestotliwosc:" Style="{DynamicResource TextBlockStyle}" Width="110" Height="25" Margin="10,40,460,35"/>
<TextBlock Text="0 Hz" FontWeight="Bold" Style="{DynamicResource TextBlockStyle}" Width="100" Height="25" Margin="135,40,345,35"/>
<TextBlock Text="Stan czujnika:" Style="{DynamicResource TextBlockStyle}" Width="120" Height="25" Margin="10,70,450,5"/>
<TextBlock Text="brak" FontWeight="Bold" Style="{DynamicResource TextBlockStyle}" Width="100" Height="25" Margin="0,70,345,5" HorizontalAlignment="Right"/>
</Grid>
And create style like this:
<Style x:Key="NamurSensorNamur" TargetType="Grid">
<Setter Property="Height" Value="100"/>
<Setter Property="Width" Value="580"/>
</Style>
But i dont know how property had I to use to declarate this textblocks.
I the future i want create dynamiclly this grid by
Style={DynamicResource NamurSensorNamur}
This is my entire usercontrol xaml:
Problem:The Combobox inside DataGrid named DG_Prices has a DataTemplate whose contentcontrol contains a Combobox.The ItemSource of this ComboBox is bound to a public property in Code Behind named LstAllPrices.ItemSource is not binding to to property named LstAllPrices which is a public property in code behind.
<UserControl x:Class="Hexa.Screens.FrmItemDetail"
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:Hexa.Screens"
mc:Ignorable="d"
Height="535" Width="605">
<UserControl.Resources>
<Style x:Key="TextBlockStyle" TargetType="{x:Type Border}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="BorderBrush" Value="Beige"/>
</Style>
<Style TargetType="Label">
<Setter Property="FontFamily" Value="Times new Roman"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="DarkBlue"/>
</Style>
<Style TargetType="GroupBox">
<Setter Property="Margin" Value="25,1,5,5"/>
<Setter Property="Background" Value="LightGray"/>
<Setter Property="BorderBrush" Value="#25A0DA"/>
<Setter Property="BorderThickness" Value="0.5,0.4,0.4,0.4"/>
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" FontWeight="Bold" FontStyle="Italic" FontFamily="Palatino Linotype" FontSize="14" Foreground="DarkRed" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Name="Style_TextBox" TargetType="TextBox">
<Setter Property="BorderBrush" Value="SkyBlue"/>
<Setter Property="Background" Value="White"/>
<Setter Property="FontFamily" Value="Times New Roman"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Height" Value="20"/>
</Style>
</UserControl.Resources>
<Canvas HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-315,-70">
<TabControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Height="606" Width="1233" Canvas.Left="0" Background="LightGray">
<TabItem Header="Main Information">
<Canvas Height="400" Width="590" Margin="0,0,0,0">
<Label Content="Code:" Canvas.Left="-198" Canvas.Top="-75"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Top="-72" Canvas.Left="-76" />
<Button Content="Filter" Canvas.Top="-74" Width="105" FontWeight="Bold" Canvas.Left="-313" FontStyle="Italic"/>
<Label Content="Creation Date:" Canvas.Top="-79" Canvas.Left="717" />
<Label Content="POS menu Filter:" Canvas.Top="-79" Canvas.Left="285" />
<Label Content="Production Date:" Canvas.Top="-81" Canvas.Left="505" />
<DatePicker Width="100" Canvas.Left="607" Canvas.Top="-81" x:Name="Dt_Prod_Date" />
<Label Content="Expiry Date:" Canvas.Top="-51" Canvas.Left="507" />
<DatePicker Width="100" Canvas.Left="608" Canvas.Top="-52" x:Name="Dt_Expiry_Date" />
<TextBox x:Name="txtPosMenuFilter" Width="115" Canvas.Top="-78" Canvas.Left="385"/>
<Border Style="{StaticResource TextBlockStyle}" Canvas.Top="-72" Canvas.Left="830">
<TextBlock Width="70" Canvas.Top="-40" Canvas.Left="-188" x:Name="txtCreationDate" Height="16" Background="White" />
</Border>
<Label Content="Last Updation Date:" Canvas.Top="-53" Canvas.Left="716" />
<Border Style="{StaticResource TextBlockStyle}" Canvas.Top="-46" Canvas.Left="830" >
<TextBlock Width="70" Canvas.Top="-40" Canvas.Left="-188" x:Name="txtUpdateDate" Height="16" Background="White" />
</Border>
<Button Content="Generate Code" Canvas.Top="-74" Background="Azure" Width="105" FontWeight="Bold" Canvas.Left="-38"/>
<TextBox x:Name="txtAutoGen_Code" Width="79" Height="17" Background="White" Canvas.Top="-72" Canvas.Left="-158" />
<GroupBox Header="Button Properties" Height="285" Width="594" Margin="0" Canvas.Top="-32" Canvas.Left="-313">
<Canvas>
<Label Content="Ticket description:" Margin="4,1,409,150" />
<TextBox x:Name="txtDesc1" Width="195" Canvas.Left="115" Canvas.Top="7" LostFocus="txtDesc1_LostFocus"/>
<Label Content="Second description:" Canvas.Left="3" Canvas.Top="27" />
<Label Content="Button sequence:" Canvas.Left="3" Canvas.Top="59" />
<ComboBox x:Name="cmbItem_Item_touch_scr_seq_2" Height="22" Canvas.Left="115" Canvas.Top="61" Width="46">
<ComboBoxItem Content="1"/>
<ComboBoxItem Content="2"/>
<ComboBoxItem Content="3"/>
<ComboBoxItem Content="4"/>
<ComboBoxItem Content="5"/>
</ComboBox>
<Label Content="UOM:" Canvas.Left="174" Canvas.Top="61" />
<ComboBox x:Name="cmbUOM" Width="92" Canvas.Left="218" Canvas.Top="62"/>
<TextBox x:Name="txtDesc2" Width="195" Canvas.Left="115" Canvas.Top="31"/>
<Label Content="Button Template Settings:" Canvas.Left="28" Canvas.Top="102" />
<Label Content="Name:" Width="56" Height="30" Canvas.Left="93" Canvas.Top="127"/>
<TextBox x:Name="txtItem_Name1" HorizontalAlignment="Right" Width="142" MaxLength="15" Text="NAME-1" Height="22" Canvas.Left="153" Canvas.Top="130" />
<TextBox x:Name="txtItem_Name2" HorizontalAlignment="Left" Width="142" MaxLength="15" Text="NAME-2" Height="22" Canvas.Left="153" Canvas.Top="158"/>
<Label Content="BackColor:" Margin="0" HorizontalAlignment="Left" Width="77" Height="25" Canvas.Left="26" Canvas.Top="187"/>
<local:UsrColorPicker x:Name="cmbItem_Item_back_color" HorizontalAlignment="Center" Width="224" Height="22" SettingConfirmed="cmbItem_Item_back_color_SettingConfirmed" Canvas.Left="101" Canvas.Top="187" />
<Label Content="ForeColor:" Margin="0" Height="24" Canvas.Left="26" Canvas.Top="219" Width="75"/>
<local:UsrColorPicker x:Name="cmbItem_Item_Fore_Color" HorizontalAlignment="Right" Width="223" Height="22" SettingConfirmed="cmbItem_Item_Fore_Color_SettingConfirmed" Canvas.Left="102" Canvas.Top="219" />
<GroupBox Height="241" Width="237" Background="DarkGray" Canvas.Left="336" Margin="0" Header="Button Template" Canvas.Top="1">
<Canvas>
<Button Canvas.Left="42" Canvas.Top="29" Width="145" Height="150" x:Name="cmdButtonTemplate" Click="cmdButtonTemplate_Click" Style="{StaticResource MyButton}">
<ContentControl HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Height="131" Canvas.Left="10" Canvas.Top="10" Width="142" >
<Canvas x:Name="ContentCanvas">
<Image Canvas.Top="5" Canvas.Left="5" x:Name="Button_Image" />
<TextBlock Canvas.Left="50" Canvas.Top="10" Text="{Binding Text, ElementName=txtItem_Name1}" Width="auto" x:Name="Button_Text_1"/>
<TextBlock Canvas.Left="50" Canvas.Top="70" Text="{Binding Text, ElementName=txtItem_Name2}" Width="auto" x:Name="Button_Text_2"/>
</Canvas>
</ContentControl>
</Button>
</Canvas>
</GroupBox>
</Canvas>
</GroupBox>
<GroupBox Height="109" Width="254" Margin="0" Header="Groups/Categories" Canvas.Top="252" Canvas.Left="-315">
<Canvas>
<Label Content="Group" Canvas.Top="12" Width="43" Canvas.Left="2"/>
<ComboBox x:Name="cmbGroupCode" Width="48" Canvas.Left="55" Canvas.Top="13" />
<TextBox x:Name="txtGroupName" Width="105" Canvas.Left="106" Canvas.Top="13" IsReadOnly="True"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="213" Canvas.Top="15" x:Name="cmdSearchGroup" />
<Label Content="Category" Canvas.Top="48" Width="57" Canvas.Left="-1"/>
<ComboBox x:Name="cmbCategoryCode" Width="48" Canvas.Left="55" Canvas.Top="48" />
<TextBox x:Name="txtCategoryName" Width="105" Canvas.Left="106" Canvas.Top="48" IsReadOnly="True"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="212" Canvas.Top="49" x:Name="cmdSearchCategory" />
</Canvas>
</GroupBox>
<GroupBox Height="109" Width="111" Margin="0" Canvas.Top="252" Header="Bonus Schema" Canvas.Left="-58">
<Canvas>
<Label Content="Amount:" Canvas.Top="1" Width="55" Canvas.Left="9"/>
<TextBox x:Name="txtBonusAmount" Width="76" Canvas.Left="12" Canvas.Top="22"/>
<Label Content="Bonus:" Canvas.Top="38" Width="43" Canvas.Left="10"/>
<TextBox x:Name="txtBonus" Width="76" Canvas.Left="13" Canvas.Top="58"/>
</Canvas>
</GroupBox>
<GroupBox Width="226" Height="109" Margin="0" Canvas.Top="252" Header="Modifiers" Canvas.Left="55">
<Canvas>
<TextBox x:Name="txtModCode1" Width="48" Canvas.Left="2" Canvas.Top="1" Height="17"/>
<TextBox x:Name="txtModname1" Width="119" Canvas.Left="60" Canvas.Top="1" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="183" Canvas.Top="3" x:Name="cmdSearchMod1" />
<TextBox x:Name="txtModCode2" Width="48" Canvas.Left="2" Canvas.Top="23" Height="17"/>
<TextBox x:Name="txtModname2" Width="117" Canvas.Left="60" Canvas.Top="23" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="182" Canvas.Top="26" x:Name="cmdSearchMod2" />
<TextBox x:Name="txtModCode3" Width="48" Canvas.Left="2" Canvas.Top="45" Height="17"/>
<TextBox x:Name="txtModname3" Width="117" Canvas.Left="60" Canvas.Top="45" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="182" Canvas.Top="47" x:Name="cmdSearchMod3" />
<TextBox x:Name="txtModCode4" Width="48" Canvas.Left="2" Canvas.Top="66" Height="17"/>
<TextBox x:Name="txtModname4" Width="116" Canvas.Left="60" Canvas.Top="66" Height="17"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="182" Canvas.Top="67" x:Name="cmdSearchMod4" />
</Canvas>
</GroupBox>
<GroupBox Height="126" Width="596" Margin="0" Canvas.Top="356" Canvas.Left="-315" Header="Pricing">
<DataGrid VerticalScrollBarVisibility="Visible" x:Name="Dg_Prices" CanUserReorderColumns="True" CanUserResizeColumns="False" CanUserResizeRows="False" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Price name">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<DataGridCell>
<ContentControl>
<ComboBox DataContext="{Binding RelativeSource={RelativeSource Self}}"
ItemsSource="{Binding LstAllPrices}"
/>
</ContentControl>
</DataGridCell>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Price Point">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DataGridCell>
<ContentControl>
<TextBox Width="100" Text="{Binding PriceName}" x:Name="AmountColumn" />
</ContentControl>
</DataGridCell>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</GroupBox>
<GroupBox Height="125" Width="620" Canvas.Left="285" Margin="0" Header="Inventory Information" Canvas.Top="-33">
<Canvas Margin="3,0,-3,0">
<Label Content="Supplier:" Canvas.Left="8" Canvas.Top="-2" />
<TextBox x:Name="txtSupplierId" Width="62" Canvas.Left="115" Canvas.Top="1"/>
<TextBox x:Name="txtSupplierName" Width="340" Canvas.Left="191" Canvas.Top="1"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="533" Canvas.Top="2" />
<Label Content="Purchase price:" Canvas.Top="22" Canvas.Left="7" />
<TextBox x:Name="txtSupplierPrice" Width="62" Canvas.Left="115" Canvas.Top="25"/>
<Label Content="VAT Code:" Canvas.Top="25" Canvas.Left="263" />
<TextBox x:Name="txtSupplierVAT" Width="90" Canvas.Left="372" Canvas.Top="25"/>
<Image Source="/Hexa;component/Images/SEARCH.png" Width="25" Height="18" Canvas.Left="469" Canvas.Top="26" />
<Label Content="15.00%" Canvas.Top="24" Width="51" Canvas.Left="491" FontWeight="Thin" x:Name="lblSupplier_Vat_Percentage"/>
<Label Content="Average Cost price:" Canvas.Top="48" Canvas.Left="5" />
<Label Content="Quantity in hand:" Canvas.Top="49" Canvas.Left="261" />
<TextBox x:Name="txtAvgCostPrice" Width="62" Canvas.Left="115" Canvas.Top="49"/>
<TextBox x:Name="txtCurrent_Qty" Width="55" Canvas.Left="373" Canvas.Top="49"/>
<Label Content="Minimum Stock:" Canvas.Top="75" Canvas.Left="6" />
<TextBox x:Name="txtMinStock" Width="62" Canvas.Left="115" Canvas.Top="74"/>
<Label Content="Maximum Stock:" Canvas.Top="73" Canvas.Left="262" />
<TextBox x:Name="txtMaxStock" Width="90" Canvas.Left="373" Canvas.Top="74"/>
</Canvas>
</GroupBox>
<GroupBox Height="166" Width="619" Canvas.Left="286" Margin="0" Canvas.Top="89" Header="Offers">
<Canvas>
<GroupBox Height="153" Width="191" Margin="0" Canvas.Top="-14" >
<Canvas Margin="0,0,0,-16">
<Label Content="Line discount" Canvas.Left="-3" Canvas.Top="-9"/>
<TextBox x:Name="txtLineDiscount" Width="76" Canvas.Left="77" Canvas.Top="-5" MaxLength="14"/>
<Label Content="Beginning:" Canvas.Top="18" Canvas.Left="11"/>
<DatePicker Width="100" Canvas.Left="77" Canvas.Top="19" x:Name="Dt_line_Disc_Begin_Date" />
<Label Content="Till:" Canvas.Top="46" Canvas.Left="11"/>
<DatePicker Width="100" Canvas.Left="77" Canvas.Top="48" x:Name="Dt_line_Disc_End_Date" />
<Label Content="Future selling price:" Canvas.Top="74" Canvas.Left="11"/>
<TextBox x:Name="txtFuture_Price_Sell" Width="53" Canvas.Left="124" Canvas.Top="77"/>
<Label Content="Activate on:" Canvas.Top="102" Canvas.Left="9"/>
<DatePicker Width="99" Canvas.Left="78" Canvas.Top="101" x:Name="Dt_line_Disc_Activation_Date" />
</Canvas>
</GroupBox>
<GroupBox Height="153" Width="412" Canvas.Left="195" Margin="0" Canvas.Top="-14" >
<Canvas>
<Label Content="Specific time price:" Canvas.Left="-3" Canvas.Top="3"/>
<TextBox x:Name="txtFuture_Selling_Price" Width="62" Canvas.Left="124" Canvas.Top="5"/>
<Label Content="Activate on:" Canvas.Left="215" Canvas.Top="3"/>
<DatePicker Width="99" Canvas.Left="296" Canvas.Top="3" x:Name="Dt_Spec_Time_Price_Activation_Date" />
<Label Content="Price on specific hours:" Canvas.Left="-3" Canvas.Top="31"/>
<TextBox x:Name="txtSpecific_Hour_Price" Width="61" Canvas.Left="125" Canvas.Top="31"/>
<Label Content="From Time:" Canvas.Left="-3" Canvas.Top="69"/>
<ComboBox x:Name="cmb_Specific_Time_Price_From_Hour" Canvas.Top="71" Canvas.Left="67"/>
<ComboBox x:Name="cmb_Specific_Time_Price_From_Minute" Canvas.Top="71" Canvas.Left="94"/>
<Label Content="Till Time:" Canvas.Top="99" Canvas.Left="-3"/>
<ComboBox x:Name="cmb_Specific_Time_Price_Till_Hour" Canvas.Top="99" Canvas.Left="68"/>
<ComboBox x:Name="cmb_Specific_Time_Price_Till_Minute" Canvas.Top="99" Canvas.Left="95"/>
<Label Content="Order Qty:" Canvas.Top="70" Canvas.Left="136"/>
<TextBox x:Name="txtOrder_Qty" Width="47" Canvas.Left="200" Canvas.Top="72"/>
<Label Content="Free Qty:" Canvas.Top="97" Canvas.Left="137"/>
<TextBox x:Name="txtFree_Qty" Width="47" Canvas.Left="200" Canvas.Top="99"/>
<Label Content="From:" Canvas.Top="71" Canvas.Left="257"/>
<DatePicker Width="99" Canvas.Left="298" Canvas.Top="69" x:Name="Dt_Specific_Time_Price_From_Date" />
<Label Content="Till:" Canvas.Top="98" Canvas.Left="259"/>
<DatePicker Width="99" Canvas.Left="298" Canvas.Top="97" x:Name="Dt_Specific_Time_Price_Till_Date" />
</Canvas>
</GroupBox>
</Canvas>
</GroupBox>
<GroupBox Height="228" Width="327" Canvas.Left="286" Margin="0" Canvas.Top="253" Header="Miscelleneous Options">
<Canvas>
<Label Content="OUT of Sales Panel" Canvas.Top="12" Canvas.Left="7"/>
<CheckBox x:Name="chkOut_Of_Sales" Canvas.Left="138" Canvas.Top="18"/>
<Label Content="OUT of STOCK Panel" Canvas.Top="53" Canvas.Left="6" />
<CheckBox x:Name="chkOut_Of_Stock" Canvas.Left="291" Canvas.Top="19"/>
<Label Content="Open price" Canvas.Top="12" Canvas.Left="192" />
<CheckBox x:Name="chkOpen_Price" Canvas.Left="138" Canvas.Top="57"/>
<Label Content="Open Description" Canvas.Top="81" Canvas.Left="190" />
<CheckBox x:Name="chkOpenDesc" Canvas.Left="291" Canvas.Top="54"/>
<Label Content="Non Stock" Canvas.Top="48" Canvas.Left="192" />
<CheckBox x:Name="chkNon_Stock" Canvas.Left="138" Canvas.Top="91"/>
<Label Content="Weighable" Canvas.Top="87" Canvas.Left="5" />
<CheckBox x:Name="chkWeighable" Canvas.Left="292" Canvas.Top="87"/>
<Label Content="No Discount" Canvas.Top="116" Canvas.Left="195" />
<CheckBox x:Name="chkNo_Discount" Canvas.Left="293" Canvas.Top="121"/>
<Label Content="Show price on button" Canvas.Top="123" Canvas.Left="5" />
<CheckBox x:Name="chkShow_Price_On_Button" Canvas.Left="138" Canvas.Top="128"/>
<Label Content="Modification AutoOpen" Canvas.Top="161" Canvas.Left="6" />
<CheckBox x:Name="chkModification_Auto_Open" Canvas.Left="138" Canvas.Top="167"/>
</Canvas>
</GroupBox>
<GroupBox Height="217" Width="287" Canvas.Left="618" Margin="0" Canvas.Top="255" Header="Active Printer">
<Canvas>
<ListBox x:Name="lstprinters" Height="190" Width="275" FontFamily="Sans Serif" FontSize="22">
<ListBoxItem Content="Printer-1"/>
<ListBoxItem Content="Printer-2"/>
<ListBoxItem Content="Printer-3"/>
<ListBoxItem Content="Printer-4"/>
<ListBoxItem Content="Printer-5"/>
<ListBoxItem Content="Printer-6"/>
<ListBoxItem Content="Printer-7"/>
<ListBoxItem Content="Printer-8"/>
</ListBox>
</Canvas>
</GroupBox>
</Canvas>
</TabItem>
</TabControl>
<Image Source="..\Images\FIRST-RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="317" />
<Image Source="..\Images\PREVIOUS_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="384" />
<Image Source="..\Images\NEXT_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="448" />
<Image Source="..\Images\LAST_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="515" />
<Image Source="..\Images\ADD_RECORD.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="598" />
<Image Source="..\Images\edit.png" Height="55" Canvas.Top="615" Canvas.Left="660" />
<Image Source="..\Images\delete.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="723" />
<Image Source="..\Images\save.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="811" x:Name="cmdSave" MouseUp="cmdSave_MouseUp" />
<Image Source="..\Images\edit.png" Height="55" Width="55" Canvas.Top="615" Canvas.Left="874" />
<Image Source="..\Images\exit.png" Height="55" Width="55" x:Name="cmdExit" MouseUp="cmdExit_MouseUp" Canvas.Left="937" Canvas.Top="615"/>
</Canvas>
code behind is:
using Hexa.Global;
using Hexa.ViewModels;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WPF.MDI;
namespace Hexa.Screens
{
public partial class FrmItemDetail : UserControl
{
DC_ItemDetails DCIM;
private List<string> _LstAllPrices;
public List<string> LstAllPrices
{
get
{
if (_LstAllPrices == null)
{
_LstAllPrices = new List<string>();
_LstAllPrices = DCIM.Lst_Prices.Select(item => item.PriceName).ToList<string>();
}
return _LstAllPrices;
}
set
{
if(_LstAllPrices==null)
{
_LstAllPrices = value;
}
}
}
public FrmItemDetail()
{
InitializeComponent();
DCIM = new DC_ItemDetails();
this.DataContext = DCIM;
cmbGroupCode.ItemsSource = DCIM.Lst_Button_Details.Where(item => item.Button_Template_Type.Equals("Group", StringComparison.Ordinal)).Select(item => item.Button_Template_Id).ToList<int>();
cmbUOM.ItemsSource = DCIM.Lst_UOM.Select(item => item.UOM).ToList<string>();
Dg_Prices.ItemsSource = this.DCIM.Lst_Prices;
}
}
}
Getting following error in output window:
System.Windows.Data Error: 40 : BindingExpression path error: 'LstAllPrices' property not found on 'object' ''ListView' (Name='')'. BindingExpression:Path=LstAllPrices; DataItem='ListView' (Name=''); target element is 'ListView' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
If MyList is a public property of the parent UserControl that returns a List<string>, you should be able to bind to it like this:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding MyList, RelativeSource={RelativeSource AncestorType=UserControl}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
I have a popUp and inside this popUp there is a wrap panel and a listbox(even without wrappanel situation is the same) I want it to be inside the main window but I can't move it there! it returns off the margins, how to fix it?
<Window x:Class="MyHeroEditor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyHeroEditor"
Title="MainWindow" Height="635.075" Width="796.643"
WindowState="Maximized"
Background="Bisque">
<Window.Resources>
<Style TargetType="ListBox" x:Key="listbox" >
<Setter Property="Height" Value="250"/>
<Setter Property="Width" Value="250" />
</Style>
<Style TargetType="Button" x:Key="Button" >
<Setter Property="Height" Value="40"/>
<Setter Property="Width" Value="55" />
</Style>
<Style TargetType="WrapPanel" x:Key="Panel" >
<Setter Property="Height" Value="250"/>
<Setter Property="Width" Value="250" />
</Style>
<Style TargetType="Image" x:Key="Image" >
<Setter Property="Height" Value="70"/>
<Setter Property="Width" Value="70" />
</Style>
</Window.Resources>
<Window.DataContext>
<local:Collections/>
</Window.DataContext>
<Canvas Name="Hero" Drop="HeroDrop" AllowDrop="True" Margin="0,0,-8,-4"
>
<WrapPanel
x:Name="HelmetPanel" Style="{StaticResource Panel}" Height="Auto" Width="Auto" />
<Button
Click="Export" Style="{StaticResource Button}" Canvas.Left="264"
Canvas.Top="389" >Export
</Button>
<Button
Click="Open" Content="Open" Style="{StaticResource Button}" Canvas.Left="15" Canvas.Top="389" />
<Button
Click="Save" Style="{StaticResource Button}" Canvas.Left="179" Canvas.Top="389" >Save
</Button>
<Button
AllowDrop="True" Style="{StaticResource Button}" Click="Helmet_Button_Click" Canvas.Left="415" Canvas.Top="26" >Шлемы
</Button>
<Button
AllowDrop="True" Style="{StaticResource Button}" Click="Armature_Button_Click" Canvas.Left="524" Canvas.Top="26" >Броня
</Button>
<Button
AllowDrop="True" Style="{StaticResource Button}" Click="Weapon_Button_Click" Canvas.Left="615" Canvas.Top="26" >Оружие
</Button>
<Button
Click="Create" Content="Create" Style="{StaticResource Button}" Canvas.Left="90" Canvas.Top="389" />
<Button
AllowDrop="True" Style="{StaticResource Button}" Click="Gloves_Button_Click" Canvas.Left="727" Canvas.Top="26" Content="Перчатки" Width="59" />
<Button
AllowDrop="True" Style="{StaticResource Button}" Click="Boots_Button_Click" Canvas.Left="824" Canvas.Top="26" Content="Сапоги" />
<Popup
Name="HelmetsPopUp" StaysOpen="False" Placement="Mouse">
<ListBox x:Name="listhelmets" Style="{StaticResource listbox}" ItemsSource="{Binding ListHelmets}"
IsSynchronizedWithCurrentItem="True" PreviewMouseDown="helmet_MouseDown" MouseDown="helmet_MouseDown"
DragLeave="helmet_DragLeave" MouseUp="Listhelmets_OnMouseUp"
SelectedValuePath="protection" >
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Style="{StaticResource Image}"/>
<TextBox Height="30" Width="30" Text="{Binding protection}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
<Popup
Name="ArmaturePopUp" StaysOpen="False" Placement="Mouse" >
<ListBox x:Name="listarmature" Style="{StaticResource listbox}" ItemsSource="{Binding ListArmature}"
IsSynchronizedWithCurrentItem="True" MouseDown="armature_MouseDown" MouseUp="Listarmature_OnMouseUp"
PreviewMouseMove="armature_PreviewMouseMove" SelectedValuePath="protection" DragLeave="armature_DragLeave"
Canvas.Left="271" Canvas.Top="51">
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Style="{StaticResource Image}"/>
<TextBox Height="30" Width="30" Text="{Binding protection}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
<Popup
Name="WeaponPopUp" StaysOpen="False" Placement="Mouse" >
<WrapPanel
Name="WeaponPanel" Style="{StaticResource Panel}">
<ListBox x:Name="listweapons" Style="{StaticResource listbox}" ItemsSource="{Binding ListWeapon}"
IsSynchronizedWithCurrentItem="True" MouseDown="weapon_MouseDown" MouseUp="Listweapons_OnMouseUp"
DragLeave="weapons_DragLeave"
PreviewMouseMove="weapons_PreviewMouseMove" SelectedValuePath="attack">
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Style="{StaticResource Image}"/>
<TextBox Height="30" Width="30" Text="{Binding _attack}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
</Popup>
<TextBox x:Name="TextBox2" Canvas.Left="29" Canvas.Top="312" Height="55" Width="130" />
<Button
Click="Reset" Style="{StaticResource Button}" Content="reset" Canvas.Left="219" Canvas.Top="327" />
<WrapPanel Height="261" Width="264" Canvas.Left="29" Canvas.Top="15">
<ListBox x:Name="listHero" Height="237" Width="100" Style="{StaticResource listbox}" ItemsSource="{Binding ListHero}"
AllowDrop="True" >
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Style="{StaticResource Image}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</WrapPanel>
<Popup Name="GlovesPopUp" StaysOpen="False">
<Canvas>
<ListBox x:Name="listgloves" Height="237" Width="131" Style="{StaticResource listbox}" ItemsSource="{Binding ListGloves}"
AllowDrop="True" Canvas.Left="723" Canvas.Top="-519" >
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Style="{StaticResource Image}"/>
<TextBox Height="30" Width="30" Text="{Binding protection}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Canvas>
</Popup>
<Popup Name="BootsPopUp" StaysOpen="False">
<ListBox x:Name="listboots" Height="237" Width="137" Style="{StaticResource listbox}" ItemsSource="{Binding ListBoots}"
AllowDrop="True" Canvas.Left="634" Canvas.Top="104" >
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Image}" Style="{StaticResource Image}"/>
<TextBox Height="30" Width="30" Text="{Binding _attack}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
</Canvas>
</Window>
Try using the XAML editor instead of the Visual Editor as the Visual one tends to glitch in certain situations.
You should move your controls between these elements:
<Window x:Class="WPFSO.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid>**Add your controls here**</Grid>
</Grid>
</Window>
My guess is you have something outside the second (inner) grid or a similar issue.
You can play with the following properties of Popup [or Tooltip] control to specify its position when it opens:
PlacementTarget (to change popup placement target):
Sample:
<Canvas Margin="5" Background="Red" Width="200" Height="150" >
<Ellipse Name="ellipse1"
Canvas.Top="60" Canvas.Left="50"
Height="85" Width="60"
Fill="Black"/>
<Popup IsOpen="True" PlacementTarget="{Binding ElementName=ellipse1}">
<TextBlock Background="LightBlue" FontSize="18">This is a Popup</TextBlock>
</Popup>
</Canvas>
Placement (Its value type is PlacementMode. A PlacementMode enumeration value that determines the orientation of the Popup control when the control opens, and that specifies how the control interacts with screen boundaries. The default is Bottom.)
Sample:
<Canvas Width="200" Height="150">
<Image Name="image1"
Canvas.Left="75"
Source="Water_lilies.jpg" Height="200" Width="200"/>
<Popup IsOpen="True" PlacementTarget="{Binding ElementName=image1}"
Placement="Bottom">
<TextBlock FontSize="14" Background="LightGreen">Placement=Bottom</TextBlock>
</Popup>
<Popup IsOpen="True" PlacementTarget="{Binding ElementName=image1}"
Placement="Top">
<TextBlock FontSize="14" Background="LightGreen">Placement=Top</TextBlock>
</Popup>
<Popup IsOpen="True" PlacementTarget="{Binding ElementName=image1}"
Placement="Left">
<TextBlock FontSize="14" Background="LightGreen">Placement=Left</TextBlock>
</Popup>
<Popup IsOpen="True" PlacementTarget="{Binding ElementName=image1}"
Placement="Right">
<TextBlock FontSize="14" Background="LightGreen">Placement=Right</TextBlock>
</Popup>
</Canvas>
HorizontalOffset
VerticalOffset
PlacementRectangle
Additional samples and info:
How to: Set the Placement Property for a Popup or Tooltip
Same problem and answer: Keep popup within window bounds:
Before:
After:
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>
I have a listbox that uses datatemplates and one of the elements in the template is a textblock. Problem is that the words won't wrap, and I don't want to set a fixed size. Anybody that knows how to resolve this problem? It's driving me crazy!
<ListBox Grid.Row=" 1" HorizontalContentAlignment="Stretch" Background="#24221f" ItemsSource="{Binding Messages}" ScrollViewer.VerticalScrollBarVisibility="Visible" ClipToBounds="False" BorderBrush="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate >
<Border BorderBrush="#24221f" BorderThickness="3" Width=" auto">
<DockPanel Background="{StaticResource blackBackground}" HorizontalAlignment="Stretch" Width="auto">
<Border BorderThickness="3" BorderBrush="Transparent">
<Image Source="{Binding IconImageUrl}" VerticalAlignment="top" Height="22" Width ="22" DockPanel.Dock="Left" />
</Border>
<Border BorderThickness="3" BorderBrush="LightGray" Height="auto" Width="auto" HorizontalAlignment="Left" VerticalAlignment="Center" DockPanel.Dock="Left">
<Image Source="{Binding ProfileImageUrl}" VerticalAlignment="Top" HorizontalAlignment="Left" Height="48" Width ="48" />
</Border>
<StackPanel Orientation="Vertical" DockPanel.Dock="Left" Margin="5,0,0,0">
<Label Content="{Binding Path=Sender}" Foreground="#feb41c" FontFamily="Verdana" FontWeight="Bold" FontSize="14" />
<TextBlock Width="100" Text="{Binding Path=ShortMessage}" Margin="10,0,0,0" Foreground="BlanchedAlmond" TextWrapping="Wrap" FontFamily="Verdana" />
<Label Content="{Binding Path=Time}" Margin="10,0,0,0" Foreground="DarkGray" FontFamily="Verdana" FontStyle="Italic"/>
</StackPanel>
</DockPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
StackPanel is Evil :=) when i have strange behaviours in a xaml which include StackPanel, switching to a Grid with right parameters ( fixed sized, or stars or "Auto" ) often fix the issue.
Note also that there is an error in your xaml since you set the DockPanel.Dock of your first image (IconImageUrl) whereas it is in the border that surrrounds it that you should be setting it. That may get the Layout to do strange things.
just try with HorizontalContentAlignment property to "Stretch" of ListBoxItems using the Style
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
and also disable the HorizontalScrollBar visibility
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
Update
<Window.Resources>
<SolidColorBrush x:Key="blackBackground" Color="Black"/>
<Style TargetType="{x:Type ListBoxItem}" >
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</Window.Resources>
<Grid>
<ListBox Grid.Row=" 1" HorizontalContentAlignment="Stretch" Background="#24221f" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemsSource="{Binding Messages}" ScrollViewer.VerticalScrollBarVisibility="Visible" ClipToBounds="False" BorderBrush="{x:Null}">
<ListBox.ItemTemplate>
<DataTemplate >
<Border BorderBrush="#24221f" BorderThickness="3" Width=" auto">
<DockPanel Background="{StaticResource blackBackground}" HorizontalAlignment="Stretch" Width="auto">
<Border BorderThickness="3" BorderBrush="Transparent">
<Image Source="{Binding IconImageUrl}" VerticalAlignment="top" Height="22" Width ="22" DockPanel.Dock="Left" />
</Border>
<Border BorderThickness="3" BorderBrush="LightGray" Height="auto" Width="auto" HorizontalAlignment="Left" VerticalAlignment="Center" DockPanel.Dock="Left">
<Image Source="{Binding ProfileImageUrl}" VerticalAlignment="Top" HorizontalAlignment="Left" Height="48" Width ="48" />
</Border>
<StackPanel Orientation="Vertical" DockPanel.Dock="Left" Margin="5,0,0,0">
<Label Content="{Binding Path=Sender}" Foreground="#feb41c" FontFamily="Verdana" FontWeight="Bold" FontSize="14" />
<TextBlock Text="{Binding Path=ShortMessage}" Margin="10,0,0,0" Foreground="BlanchedAlmond" TextWrapping="Wrap" FontFamily="Verdana" />
<Label Content="{Binding Path=Time}" Margin="10,0,0,0" Foreground="DarkGray" FontFamily="Verdana" FontStyle="Italic"/>
</StackPanel>
</DockPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
I think this thread answer's your question, see the accespted answer by "Nash" - Force TextBlock to wrap in WPF ListBox
( and remember to upvote the answer the the linked thread if it helps you :) )