How to change the color of the a WPF “?
You can set the Background: <Separator Background=”Red”/>
You can set the Background: <Separator Background=”Red”/>
You can define it as an application resource: <Application x:Class=”xxxxxx” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:clr=”clr-namespace:System;assembly=mscorlib” StartupUri=”MainWindow.xaml”> <Application.Resources> <clr:String x:Key=”MyConstString”>My string</clr:String> </Application.Resources> </Application>
You can use the FocusManager.FocusedElement attached property for this purpose. Here’s a piece of code that set the focus to TxtB by default. <StackPanel Orientation=”Vertical” FocusManager.FocusedElement=”{Binding ElementName=TxtB}”> <TextBox x:Name=”TxtA” Text=”A” /> <TextBox x:Name=”TxtB” Text=”B” /> </StackPanel> You can also use TxtB.Focus() in your code-behind if you don’t want to do this in XAML.
Instead of putting (as in your example) a button directly on the canvas, you could put a stackpanel on the canvas, horizontally aligned, and put the two buttons in there. Like so: <Canvas> <StackPanel Canvas.Left=”100″ Canvas.Top=”100″ Orientation=”Horizontal”> <Button>Button 1</Button><Button>Button 2</Button> </StackPanel> </Canvas> I think that it’s quite flexible when you use more than 1 layout … Read more
Here’s a version of the MessageBoxEx helper class posted in the other thread that uses WPF style message boxes (Note that you still need to reference System.Drawing): using System; using System.Text; using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; using System.Drawing; public class MessageBoxEx { private static IntPtr _owner; private static HookProc _hookProc; private static IntPtr _hHook; … Read more
Set the width for the data grid to “Auto”. You’re allowing the columns to resize correctly within the grid itself, but you’ve hard-wired the width to 200. UPDATE: Base on @micas’s comment, I may have misread. If that’s the case, try using 100 for the left column’s width and 100* for the right column (note … Read more
No, there is no way of having nested comments in XAML. You could use the mc:Ignorable attribute on your root element, and any attribute or element prefixed with that value will be ignored E.g: <UserControl … mc:Ignorable=”i”> <!– Ignore Text attribute –> <TextBlock i:Text=”Hello” /> <!– Ignore entire button –> <i:Button> </i:Button> </UserControl> Note that … Read more
I checked your XAML, it works fine – e.g. both labels have a gray foreground. My guess is that you have some style which is affecting the way it looks… Try moving your XAML to a brand-new window and see for yourself… Then, check if you have any themes or styles (in the Window.Resources for … Read more
Alternatively, you could replace your XAML with this: <TextBlock Margin=”0,0,5,0″ Text=”{Binding ElementName=EditListBox, Path=SelectedItems.Count}”/> <TextBlock> <TextBlock.Style> <Style TargetType=”{x:Type TextBlock}”> <Setter Property=”Text” Value=”items selected”/> <Style.Triggers> <DataTrigger Binding=”{Binding ElementName=EditListBox, Path=SelectedItems.Count}” Value=”1″> <Setter Property=”Text” Value=”item selected”/> </DataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> Converters can solve a lot of binding problems but having a lot of specialized converters gets very messy.
You can use a data trigger and set the binding RelativeSource to Self. Data Triggers allow binding and bindings lets you have converters. Example: <Button Content=”I change colour depending on my width for some reason”> <Button.Triggers> <DataTrigger Binding=”{Binding Path=Width, RelativeSource={RelativeSource Self}, Converter={StaticResource isLessThanConverter}, ConverterParameter=50}” Value=”True”> <Setter Property=”Button.Background” Value=”Red” /> <DataTrigger> <Button.Triggers> <Button> Reference