小编akj*_*shi的帖子

WPF验证(IDataErrorInfo)和选项卡聚焦问题

我有一个TextBox实现的对象的属性绑定IDataErrorInfo.我成立Validation.ErrorTemplateTextBox,并能正常工作.问题是我在a上有这些TabControl,如果我将标签更改为另一个标签然后返回到初始标签(其中TextBox),则验证模板不再显示.它看起来像是经过验证的(就像值是正确的),但实际上并非如此.

这是IDataErrorInfo对象 - 请注意,"正确"值是一个长度为2的字符串:

public class Presenter : IDataErrorInfo
{
    public Presenter()
    {
        this.Property = String.Empty;
    }

    public string Property { get; set; }

    public string Error { get { return null; } }

    public string this[string columnName]
    {
        get
        {
             if (columnName == "Property")
             {
                if (this.Property.Length == 2)
                   return null;
                else
                   return "Invalid property length!";
             }
             else return null;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是XAML:

<TabControl …
Run Code Online (Sandbox Code Playgroud)

c# validation wpf tabcontrol idataerrorinfo

12
推荐指数
1
解决办法
5184
查看次数

拖放时滚动(WPF)

好吧,伙计们,我一直在为这个问题疯狂地挠头,并花了几个小时试图研究它是如何工作的但是我还没有找到答案,如果你希望看到我的任何一个SRC可以随意询问我和我会看看能不能帮忙.

基本上我遇到的问题是TreeView我的应用程序中有一个文件夹,即:

Catalog

  Brands
    Nike
    Adidas
    Lactose

  Styles
    Sandles
    Trainers
    Boots
Run Code Online (Sandbox Code Playgroud)

我试图解决的问题是,当我拖动文件夹时(这是在我DragDropManager班级中处理的),我无法向上或向下滚动(只显示一个可爱的停止标志).我也无法在树视图中找到一个滚动条,所以我不确定它是如何生成的(这不是我自己的软件,我最近开始为一家公司工作所以我不熟悉代码而没有其他人似乎知道.)

如果我想从顶部移动到最底部,这是一个问题.

滚动工作正常,无需拖动.

如果有人希望看到我的代码的任何部分随意问,因为我不确定实际向你们展示什么.

我已经阅读了很多文章,我只是在摸不着头脑.

c# wpf treeview scroll drag-and-drop

12
推荐指数
1
解决办法
1万
查看次数

如何设置DataGridTextColumn文本颜色?

我正在尝试更改DataGridTextColumn的颜色.

这是我正在做的事情:

<DataGridTextColumn 
    Header="Status" 
    Binding="{Binding IsActive, 
               Converter= {StaticResource BoolToStatusConverter}}"
    Foreground="{Binding Path=IsActive,
               Converter={StaticResource BoolToColorConverter}}"/>
Run Code Online (Sandbox Code Playgroud)

文本设置正确,但颜色不会改变,我收到以下错误:

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or 
FrameworkContentElement for target element. BindingExpression:Path=IsActive; 
DataItem=null; target element is 'DataGridTextColumn' (HashCode=40349079); target 
property is 'Foreground' (type 'Brush')
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能工作?

c# wpf xaml wpfdatagrid datagridtextcolumn

12
推荐指数
2
解决办法
2万
查看次数

我应该使用WPF转换器还是触发器?

我想知道你如何决定何时使用converters以及何时使用triggers.我更喜欢在GUI上使用触发器来操作(比如显示/隐藏控件,改变它们的外观等).

前段时间我使用了一个BooleanToVisibilityConverter用于此目的,但现在,我只是不需要它,我做所有与visibility使用触发器相关的事情,我甚至开始思考" 由MS团队创建一个目的是什么BooleanToVisibilityConverter?" .通常,当我有可能尝试使用声明方式编写代码时 - 在本例中 - XAML.

你对此有何看法?

.net wpf xaml triggers converter

12
推荐指数
1
解决办法
3342
查看次数

SignalR和Android,我的选择是什么?

我正在开发一个ASP.NET MVC应用程序,浏览器中的JavaScript和本机Android应用程序都使用它,我希望使用SignalR.这当然在浏览器中没有问题,但我不知道如何从Android应用程序界面.

是我唯一的选择:

  1. 找到预先存在的Android SignalR库.要么
  2. 编写自定义代码与服务器端SignalR接口连接?

android signalr

12
推荐指数
2
解决办法
6346
查看次数

rapidJSON添加一个结构数组

我希望能够使用rapidJSON创建以下JSON输出

{
    "year": 2013,
    "league": "national",
    "teams": [
        {
            "teamname": "reds",
            "teamcity": "cincinnati",
            "roster": [
                {
                    "playername": "john",
                    "position": "catcher"
                },
                {
                    "playername": "joe",
                    "position": "pitcher"
                }
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这是有效的JSON ...在JSONLint.com上验证我知道如何创建文档并使用AddMember添加"年份"和"联盟".

我无法弄清楚并且没有看到任何关于如何添加具有"团队"或"名册"结构的数组的示例

如何添加"团队",这是一组结构?任何帮助或指向我的例子都会很棒.

arrays json struct

12
推荐指数
2
解决办法
2万
查看次数

在WPF中,如何实现ICommandSource以使我的自定义控制能力能够使用来自xaml的命令?

您能否提供一个示例,了解如何实现ICommandSource界面.因为我希望我的UserControl,没有能力在xaml中指定命令,才能拥有此功能.并且能够在用户点击时处理该命令CustomControl.

.net c# wpf routed-commands

11
推荐指数
1
解决办法
4866
查看次数

x:样式中的Key和TargetType

使用此声明是否有任何区别(或优势):

Style x:Key="{x:Type DataGridCell}" TargetType="{x:Type DataGridCell}"
Run Code Online (Sandbox Code Playgroud)

省略x:Key属性?

我认为WPF x:Type在引擎盖下指定了相同的关键.

silverlight wpf xaml targettype

11
推荐指数
1
解决办法
5728
查看次数

ControlTmplate与DataTrigger相比.DataTemplate与DataTemplateSelector

我有一个通用控件,它根据ViewModel中的type属性显示一个编辑器.目前它已经实现使用Control,ControlTemplate并且DataTrigger像这样 -

<Control
   x:Name="MainControl"
   Grid.Column="1"
   TargetUpdated="OnTargetUpdated">
        <Control.Style>
            <Style>
                <Style.Triggers>
                    <DataTrigger
                        Binding="{Binding Path=EditorType}"
                        Value="{x:Static view:EditorType.Bool}">
                        <Setter
                            Property="Control.Template"
                            Value="{StaticResource boolTemplate}" />
                    </DataTrigger>
                    <DataTrigger
                        Binding="{Binding Path=EditorType}"
                        Value="{x:Static view:EditorType.Text}">
                        <Setter
                            Property="Control.Template"
                            Value="{StaticResource textTemplate}" />
                    </DataTrigger>
                    <DataTrigger
                        Binding="{Binding Path=EditorType}"
                        Value="{x:Static view:EditorType.Integer}">
                        <Setter
                            Property="Control.Template"
                            Value="{StaticResource integerTemplate}" />
                    </DataTrigger>
                    ...
                    ....
                </Style.Triggers>
            </Style>
     </Control.Style>
</Control>
Run Code Online (Sandbox Code Playgroud)

现在,同样可以利用来实现ContentPresenter,DataTemplateDataTemplateSelector这样的-

<local:EditorTemplateSelector
    BoolEditorTemplate="{StaticResource boolTemplate}"
    TextEditorTemplate="{StaticResource textTemplate}"
    IntegerEditorTemplate="{StaticResource integerTemplate}"
    ...
    ....
    x:Key="EditorTemplateSelector">
</local:EditorTemplateSelector>

<ContentPresenter
    ContentTemplateSelector="{Binding Source={StaticResource EditorTemplateSelector}}"
    Content="{Binding}"
    TargetUpdated="OnTargetUpdated">
</ContentPresenter>

// …
Run Code Online (Sandbox Code Playgroud)

wpf datatrigger datatemplate controltemplate datatemplateselector

11
推荐指数
1
解决办法
1万
查看次数

WPF堆栈面板集中对齐

我希望能够集中对齐堆栈面板中的按钮.按钮数是动态的,并在加载控件时生成.例如,如果生成1个按钮,则此按钮应放在控件的中心.如果显示5个按钮,那么所有5个按钮应相互水平对齐,但是控件的中心位置.

另一种方法是让控件根据其内容动态调整大小,以便使用更多按钮更宽,然后在页面上水平对齐用户控件,但我不确定如何处理任何一种解决方案?

有人有什么想法吗?

.net silverlight wpf

11
推荐指数
2
解决办法
2万
查看次数