我有一个TextBox
实现的对象的属性绑定IDataErrorInfo
.我成立Validation.ErrorTemplate
的TextBox
,并能正常工作.问题是我在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) 好吧,伙计们,我一直在为这个问题疯狂地挠头,并花了几个小时试图研究它是如何工作的但是我还没有找到答案,如果你希望看到我的任何一个SRC可以随意询问我和我会看看能不能帮忙.
基本上我遇到的问题是TreeView
我的应用程序中有一个文件夹,即:
Catalog
Brands
Nike
Adidas
Lactose
Styles
Sandles
Trainers
Boots
Run Code Online (Sandbox Code Playgroud)
我试图解决的问题是,当我拖动文件夹时(这是在我DragDropManager
班级中处理的),我无法向上或向下滚动(只显示一个可爱的停止标志).我也无法在树视图中找到一个滚动条,所以我不确定它是如何生成的(这不是我自己的软件,我最近开始为一家公司工作所以我不熟悉代码而没有其他人似乎知道.)
如果我想从顶部移动到最底部,这是一个问题.
滚动工作正常,无需拖动.
如果有人希望看到我的代码的任何部分随意问,因为我不确定实际向你们展示什么.
我已经阅读了很多文章,我只是在摸不着头脑.
我正在尝试更改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)
我该怎么做才能工作?
我想知道你如何决定何时使用converters
以及何时使用triggers
.我更喜欢在GUI上使用触发器来操作(比如显示/隐藏控件,改变它们的外观等).
前段时间我使用了一个BooleanToVisibilityConverter
用于此目的,但现在,我只是不需要它,我做所有与visibility
使用触发器相关的事情,我甚至开始思考" 由MS团队创建一个目的是什么BooleanToVisibilityConverter
?" .通常,当我有可能尝试使用声明方式编写代码时 - 在本例中 - XAML.
你对此有何看法?
我正在开发一个ASP.NET MVC应用程序,浏览器中的JavaScript和本机Android应用程序都使用它,我希望使用SignalR.这当然在浏览器中没有问题,但我不知道如何从Android应用程序界面.
是我唯一的选择:
我希望能够使用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添加"年份"和"联盟".
我无法弄清楚并且没有看到任何关于如何添加具有"团队"或"名册"结构的数组的示例
如何添加"团队",这是一组结构?任何帮助或指向我的例子都会很棒.
您能否提供一个示例,了解如何实现ICommandSource
界面.因为我希望我的UserControl
,没有能力在xaml中指定命令,才能拥有此功能.并且能够在用户点击时处理该命令CustomControl
.
使用此声明是否有任何区别(或优势):
Style x:Key="{x:Type DataGridCell}" TargetType="{x:Type DataGridCell}"
Run Code Online (Sandbox Code Playgroud)
省略x:Key
属性?
我认为WPF x:Type
在引擎盖下指定了相同的关键.
我有一个通用控件,它根据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
,DataTemplate
而DataTemplateSelector
这样的-
<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
我希望能够集中对齐堆栈面板中的按钮.按钮数是动态的,并在加载控件时生成.例如,如果生成1个按钮,则此按钮应放在控件的中心.如果显示5个按钮,那么所有5个按钮应相互水平对齐,但是控件的中心位置.
另一种方法是让控件根据其内容动态调整大小,以便使用更多按钮更宽,然后在页面上水平对齐用户控件,但我不确定如何处理任何一种解决方案?
有人有什么想法吗?
wpf ×8
c# ×4
.net ×3
xaml ×3
silverlight ×2
android ×1
arrays ×1
converter ×1
datatemplate ×1
datatrigger ×1
json ×1
scroll ×1
signalr ×1
struct ×1
tabcontrol ×1
targettype ×1
treeview ×1
triggers ×1
validation ×1
wpfdatagrid ×1