嗨,我有一个DatagridView,我希望它根据每行中的数据更改背景颜色.
防爆.
| 人1 | 人2 | 人3 |
| ---- ---- 100 | --- 200 ----- | ----- 150 ---- |
| ---- 300 ---- | --- 100 ----- | ------ 50 ---- |
在第一行,我希望它使"100"具有红色背景颜色和"200"绿色.要么.最低值=红色最高=绿色
现在的问题是我使用BindingList作为我的数据,并使用INotifyPropertyChanged更新异步.因此,每次更新其中一个值时,我需要一些检查方法.
DataGridView是否有任何有用的事件?
这是关于在WPF应用程序中将图像保存到文件保持宽高比的后续问题
我知道如何缩放图像,但如何扩展画布大小,以确保图像仍然具有所需的宽度和高度.在这个例子中它的250x250但它的动态.
我创建了这个插图来展示我想要帮助的东西.

我找不到任何方法来扩展BitmapImage的画布,也没有办法以正确的大小创建内存图像,使用透明背景,然后将两个图像合并在一起.
我正试图将一些货币对齐到右边:
double number1 = 150.45;
double number2 = 1400.95;
//Output kr. 150,45
Console.WriteLine("{0:c2}", number1);
//Output kr. 1.400,95
Console.WriteLine("{0:c2}", number2);
Run Code Online (Sandbox Code Playgroud)
但我希望我的输出看起来像这样.
//Output kr. 150.45
//Output kr. 1.400,95
Run Code Online (Sandbox Code Playgroud)
数字是否与右边对齐?
我正在寻找一个Visual Studio 2010插件来帮助我清理ASP.NET MVC项目中的CSS.
我们很多人在同一个网站上工作,在我发布之前,我想清理CSS以确保没有未使用的选择器.
我知道Firefox有插件,但它们不会捕获任何动态加载的CSS,通常它们只检查一页.
我正在WPF中构建一个登录屏幕.我试图找出如何绑定我的代码的一部分只有在大写锁定键打开时才可见.
<StackPanel Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="1" Orientation="Horizontal">
<Image Source="../../../Resources/Icons/109_AllAnnotations_Warning_16x16_72.png" Height="16" Width="16"/>
<Label>Caps lock is on</Label>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
我更喜欢只有xaml绑定的解决方案.
想想我一直在看我的代码太多了.
但我的问题是我有一个无序列表,我需要选择具有最高数字的对象接近或等于输入.
我创建了这个小样本来说明我想要做的事情.
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
var persons = new List<Person>
{
new Person {Age = 10, Name = "Aaron"},
new Person {Age = 15, Name = "Alice"},
new Person {Age = 20, Name = "John"},
new Person {Age = 22, Name = "Bob"},
new Person {Age = 24, Name = "Malcom"}
};
int i = 17; //should return 'Alice 15'
int y = …Run Code Online (Sandbox Code Playgroud) 嗨,我创建了这个小例子,我想扩展它以支持排序.
public class Country
{
public string Name { get; set; }
public int SortOrder { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的xaml:
<TreeView Name="CountryTreeView" ItemsSource="{Binding}">
<TreeView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
Run Code Online (Sandbox Code Playgroud)
代码隐藏:
readonly ObservableCollection<Country> Countries;
public MainWindow()
{
InitializeComponent();
Countries = new ObservableCollection<Country>
{
new Country{Name = "Denmark", SortOrder = 0},
new Country{Name = "Norway", SortOrder = 1},
new Country{Name = "Sweden", SortOrder = 2},
new Country{Name = "Iceland", SortOrder = 3},
new Country{Name = "Greenland", SortOrder = 4}, …Run Code Online (Sandbox Code Playgroud) 嗨,只想知道它是否可以在xaml中绑定到列表,其中值具有一定值.防爆.在下面的例子中,Xaml是否只能显示项目,其中Price = 20?
我问,因为我要绑定一个包含另一个列表的对象列表,我只想显示某个项目,具体取决于值.因此,我试图避免使用C#解决方案.
MainWindow.xaml
<Window x:Class="Binding_Test.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>
<ListView ItemsSource="{Binding}"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml.cs
public MainWindow()
{
DataContext = BuildList();
InitializeComponent();
}
List<Product> BuildList()
{
var list = new List<Product>();
var y = 1;
for (var i = 0; i < 100; i++)
{
list.Add(new Product{Name = string.Format("Item {0}",i), Price = y++ * 10 });
if (y > 3)
y = 1;
}
return list;
}
Run Code Online (Sandbox Code Playgroud)
Product.cs
public class Product
{
public string Name { get; …Run Code Online (Sandbox Code Playgroud) 我创造了这个DataTemplate,但我无法弄清楚如何添加style一个DataTrigger到IMG变量。
我希望img根据Suppliers[i].Stock(int)的值显示不同的图像
资源图标
Properties.Resources.InStock => Suppliers[i].Stock > 0
Properties.Resources.OutOfStock => Suppliers[i].Stock = 0
Properties.Resources.Unknown => Suppliers[i].Stock = null
Run Code Online (Sandbox Code Playgroud)
我的代码到目前为止。
private DataTemplate GetStockTemplate(int i)
{
var template = new DataTemplate();
var wp = new FrameworkElementFactory(typeof (WrapPanel));
wp.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Right);
wp.SetValue(WrapPanel.OrientationProperty, Orientation.Horizontal);
var tx = new FrameworkElementFactory(typeof (TextBox));
tx.SetBinding(TextBox.TextProperty, new Binding("Suppliers[" + i + "].Stock") {StringFormat = "{0:n0}"});
tx.SetValue(TextBoxBase.IsReadOnlyProperty, true);
tx.SetValue(Control.BorderThicknessProperty, new Thickness(0));
tx.SetValue(Control.BackgroundProperty, Brushes.Transparent);
tx.SetValue(TextBox.TextAlignmentProperty, TextAlignment.Right);
wp.AppendChild(tx);
var img = …Run Code Online (Sandbox Code Playgroud) 我知道如何绑定到Count,但是如果我只想要类型为Product的计数,我该怎么做呢
<TextBlock Text="{Binding Items.Count}" />
Items = new ObservableCollection<object>();
Run Code Online (Sandbox Code Playgroud)
我尝试使用属性,但是在添加或删除项目时,我遇到了保持同步的问题.
public int ProductCount
{
get
{
return Items.Cast<object>().Count(item => item.GetType() == typeof (ProductViewModel));
}
}
Run Code Online (Sandbox Code Playgroud) c# ×9
.net ×6
wpf ×6
c#-4.0 ×3
asp.net-mvc ×1
binding ×1
css ×1
datagridview ×1
datatemplate ×1
linq ×1
styles ×1
treeview ×1
winforms ×1
xaml ×1