考虑我绑定到ComboBox的键值对集合(Ex键= MSFT值= MSFT Microsoft).DisplayMemeberPath =价值.以下需要完成
在选择项目时,只需要在组合中显示键,
用户还可以在组合中键入一个全新的值.
我不能提出支持这两个功能的解决方案.解决一个打破另一个.
<ComboBox IsTextSearchEnabled="True" Name="cmbBrokers" IsEditable="True"
ItemsSource="{Binding BrokerCodes}" SelectedValuePath="Key"
DisplayMemberPath="Value" Text="{Binding SelectedBroker, Mode=TwoWay}">
Run Code Online (Sandbox Code Playgroud) 有时当我调用类的.ToString()方法时,它会返回类的完全限定名.但是对于某些类的/ struct(例如Int32),它返回一个字符串对应的对象(整数的值).这是否意味着Int32该类重写该ToString()方法,并且返回完全限定名称的类不会覆盖它,而只是调用base的(Object's)ToString()方法?Object.ToString()实现是否只返回类的完全限定名称?
将问题陈述简化为int of List,让我说我有这个
List<int> range = new List<int>(10) { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
Run Code Online (Sandbox Code Playgroud)
用户输入24,我需要一个早期饲料值为20,晚期饲料值为30个
用户输入99,我需要一个早期饲料值为90,晚期饲料值为100个
用户输入20,我需要一个早期饲料值作为20和后期饲料值为20
是否有Lamba Expression或linq语句来获得此类结果.
我真正的输入不是int的列表,我刚刚对它进行了简化,更加热衷于lamba或linq表达式以获得结果
我试图根据它的值更新文本块的颜色.看似简单然而不起作用.
这是文本块xaml.
<TextBlock
Grid.Column="1"
Grid.Row="1"
Text="{Binding Path=GL, StringFormat={}{0:N0}}"
HorizontalAlignment="Left"
FontFamily="Verdana"
Foreground="Tomato"
FontWeight="Bold"
VerticalAlignment="Center"
Margin="5,2,5,0"
FontSize="18"
>
<TextBlock.Resources>
<converters:ColorConverter x:Key="CoConverter"></converters:ColorConverter>
</TextBlock.Resources>
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text, Converter={StaticResource ResourceKey=CoConverter}}" Value="true">
<Setter Property="TextBlock.Foreground" Value="LimeGreen" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
Run Code Online (Sandbox Code Playgroud)
转换器
public class ColorConverter : MarkupExtension, IValueConverter
{
#region IValueConverter Members
public object Convert(object value,
Type targetType,
object parameter,
System.Globalization.CultureInfo culture)
{
if (value == null)
return false;
if (value.ToString().Length == 0)
return false;
if (System.Convert.ToDouble(value) >= 0)
return true;
return …Run Code Online (Sandbox Code Playgroud)