wpf-4.0

WPF Datagrid DataGridTextColumn does not allow decimal

孤者浪人 提交于 2020-01-16 15:21:24
问题 I am not able to enter decimal values in DataGridTextColumn. Below link suggest that we cannot enter decimal values if UpdateSourceTrigger = PropertyChanged. WPF DataGridTextColumn binding doesn't accept decimals But my requirement is that I have to keep UpdateSourceTrigger = PropertyChanged. Please suggest. Below is the code snippet for my Datagrid: <DataGrid x:Name="MyDataGrid" HorizontalAlignment="Left" CanUserResizeColumns="True" VerticalAlignment="Stretch" ItemsSource="{Binding

Binding to interface typed properties

你说的曾经没有我的故事 提交于 2020-01-14 12:37:22
问题 I just got bit by yet another binding oddity in WPF. Consider the following class and its IStupid typed property called MyStupid : public struct DumbClass { public IStupid MyStupid { get { return new IsStupid(); } } } public interface IStupid{} public class IsStupid : IStupid{} Now consider the following binding to a ListBox : var items = new List<DumbClass>(new []{new DumbClass(), new DumbClass(), new DumbClass()}); OptListBox.ItemsSource = items; There is nothing special about the xaml:

Changing dynamically created button's background in WPF

こ雲淡風輕ζ 提交于 2020-01-14 03:16:08
问题 I have the following code to dynamically create and add a button to a panel: StackPanel topPanel=...; Button button=new Button(); button.Content="New Button "+topPanel.Children.Count; // Set button background to a red/yellow linear gradient // Create a default background brush var bgBrush=new LinearGradientBrush(new GradientStopCollection( new GradientStop[] {new GradientStop(Color.FromRgb(255,255,200),0.5), new GradientStop(Color.FromRgb(255,200,200),0.5)})); // Create a more intense mouse

The difference between GotFocus and GotKeyboardFocus

一世执手 提交于 2020-01-13 07:57:13
问题 What is the difference(s) between GotFocus and GotKeyboardFocus -and similarly LostFocus and LostKeyboardFocus ? Sorry for the simple question, but, I googled it and read a lot of blog posts, but I'm still confused. It seems nobody knows exactly what is the difference ): UPDATE: My usage: I am creating a custom control by extending Control class. Something like ComboBox but with some other effects. I'm trying to open and close a Popup by setting a property: IsDropDownOpen just like a ComboBox

How to handle whitespace in DataTrigger binding for WPF DataGrid?

为君一笑 提交于 2020-01-06 02:36:45
问题 I am using autogenerating datagrid and binding it to a DataTable.This DataTable has columns with whitespaces like 'Last Value'. Now I need to add a datatrigger to apply some style as shown below: <DataGrid.Resources> <Style x:Key="DgStyle" TargetType="{x:Type TextBlock}"> <Setter Property="TextAlignment" Value="Right"/> <Style.Triggers> <DataTrigger Binding="{Binding Last Value, Converter= {StaticResource DecimalToBoolConverter}}" Value="True"> <Setter Property="Foreground" Value="Red" /> <

Issue with x:TypeArguments and generic List class in XAML

风格不统一 提交于 2020-01-02 02:21:14
问题 I created the following markup for a loose XAML file. <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"> <scg:List x:TypeArguments="sys:String"> HelloWorld </scg:List> </StackPanel> But I get this error when I run the loose XAML in IE: The tag 'List' does not exist in XML namespace 'clr

Issue with x:TypeArguments and generic List class in XAML

僤鯓⒐⒋嵵緔 提交于 2020-01-02 02:21:05
问题 I created the following markup for a loose XAML file. <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"> <scg:List x:TypeArguments="sys:String"> HelloWorld </scg:List> </StackPanel> But I get this error when I run the loose XAML in IE: The tag 'List' does not exist in XML namespace 'clr

WPF Cursor on a partially transparent image

核能气质少年 提交于 2020-01-01 09:19:12
问题 I have a png that contains transparent regions and I set it to the image tag but how am I able to set the cursor to a hand when it is over an opaque part of the image? Thanks Tony 回答1: To do this you will need to look at the bitmap itself. WPF's hit testing mechanism considers any pixel painted ith a "transparent" brush to still be clickable even though invisible. This is normally a good thing but gets in the way of what you're trying to do. Because a .png paints with the transparent brush,

Getting WPF Data Grid Context Menu Click Row

家住魔仙堡 提交于 2019-12-29 17:42:47
问题 I have a WPF DataGrid <DataGrid AutoGenerateColumns="False" Name="dataGrid1" IsReadOnly="True" > <DataGrid.Columns> <DataGridTextColumn Header="Site" Binding="{Binding Site}" Width="150" /> <DataGridTextColumn Header="Subject" Binding="{Binding Subject}" Width="310" /> </DataGrid.Columns> <DataGrid.ContextMenu> <ContextMenu> <MenuItem Header="Delete" Click="Context_Delete"> <MenuItem.Icon> <Image Width="12" Height="12" Source="Images/Delete.png" /> </MenuItem.Icon> </MenuItem> </ContextMenu>

How to create Custom Property for WPF DataGridTextColumn

六月ゝ 毕业季﹏ 提交于 2019-12-24 15:13:18
问题 I want to add custom property in WPF DataGridTextColumn, How i can add custom property, and Bind it from C# code and retrieve it by C# code. 回答1: I just got answer for it First Create public static class dataGridTag { public static readonly DependencyProperty TagProperty = DependencyProperty.RegisterAttached( "Tag", typeof(object), typeof(dataGridTag), new FrameworkPropertyMetadata(null)); public static object GetTag(DependencyObject dependencyObject) { return dependencyObject.GetValue