小编Vin*_*ANG的帖子

WPF - 将组合框项目前景绑定到其值

我创建了一个组合框,列出了 System.Windows.Media.Colors 预定义的颜色,使用了这个问题中讲述的方法:How can I list color in WPF with XAML?

我现在的 XAML 代码是:

<Window ...>
    <Window.Resources>
        <ObjectDataProvider 
            ObjectInstance="{x:Type Colors}" MethodName="GetProperties" x:Key="ColorList" />
        <local:StringToBrushConverter x:Key="FontColorConversions" />
    </Window.Resources>

    <Grid Background="Black">

        ...

        <ComboBox  Grid.Column="1" Grid.Row="1" Height="22" Width="240" 
                   VerticalAlignment="Center" HorizontalAlignment="Left"
                   ItemsSource="{Binding Source={StaticResource ColorList}}"
                   SelectedValue="{Binding FontColor, Mode=TwoWay}"
                   DisplayMemberPath="Name"
                   SelectedValuePath="Name">
            <ComboBox.ItemContainerStyle>
                <Style TargetType="ComboBoxItem">
                    <Setter Property="Foreground" Value="{Binding Converter={StaticResource FontColorConversions}}"/>
                </Style>
            </ComboBox.ItemContainerStyle>
        </ComboBox>
        ...
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

此外,请注意,我将 SelectedValue 绑定到 VM 类的 FontColor 属性,该属性是字符串类型。

class FontSetting : INotifyPropertyChanged
{
    private string _fontColor = "Lavender";   // initial color …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf combobox

6
推荐指数
1
解决办法
3994
查看次数

如何查看代码指标lke扇入/扇出与NDepend

我已经安装了NDepend(14天试用版)作为Visual Studio 2015扩展,它现在可以使用了.

我想在我的解决方案中获得一些类的一些指标:

  • 标识符的长度
  • 扇入/扇出
  • 加权方法
  • 类对象的耦合

我没有从官方网站上找到任何有用的指示,有人知道吗?

谢谢.

.net c# ndepend code-metrics

3
推荐指数
1
解决办法
413
查看次数

WPF - 将 TextBox 的 FontFamily 绑定到 ComboBox

我知道这篇文章:TextBox FontFamily Binding,看起来与我的问题相似,但我的情况要简单得多,我想将 TextBox 控件的 FontFamily 属性绑定到 ComboBox,当 ComboBox 的值发生变化时,TextBox 的内容相应变化。我没有使用 VM 或依赖属性,我遵循了本教程:https : //dotnetstories.wordpress.com/2011/07/31/using-type-converters-in-wpf/

并提出:

<Window x:Class="NumericControlTest.MainWindow"
    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:NumericControlTest"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">

<Window.Resources>
    <local:FontFamilyConversions x:Key="FontFamilyConversions" />
</Window.Resources>

<DockPanel>

    <ComboBox  DockPanel.Dock="Top" x:Name="Fonttype" >
        <ComboBoxItem IsSelected="True">Arial</ComboBoxItem>
        <ComboBoxItem>Batang</ComboBoxItem>
        <ComboBoxItem>BatangChe</ComboBoxItem>
        <ComboBoxItem>Gungsuh</ComboBoxItem>
        <ComboBoxItem>GungsuhChe</ComboBoxItem>
        <ComboBoxItem>Courier New</ComboBoxItem>
    </ComboBox>
    <TextBox x:Name="editor" FontSize="16" FontFamily="{Binding Path=SelectedValue, ElementName=Fonttype, Mode=OneWay, Converter={StaticResource FontFamilyConversions}}" >

    </TextBox>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)

using System.Windows.Data;
using System.Windows.Media;

namespace NumericControlTest
{
    class FontFamilyConversions : IValueConverter
    {
        public object Convert(object value, System.Type targetType, object …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf

2
推荐指数
1
解决办法
2427
查看次数

标签 统计

c# ×3

data-binding ×2

wpf ×2

.net ×1

code-metrics ×1

combobox ×1

ndepend ×1