我正在尝试Readonly使用OneWayToSourceas模式绑定到属性,但似乎无法在XAML中完成:
<controls:FlagThingy IsModified="{Binding FlagIsModified,
ElementName=container,
Mode=OneWayToSource}" />
Run Code Online (Sandbox Code Playgroud)
我明白了:
无法设置属性"FlagThingy.IsModified",因为它没有可访问的set访问器.
IsModified是只读DependencyProperty的FlagThingy.我想将该值绑定到FlagIsModified容器上的属性.
要明确:
FlagThingy.IsModified --> container.FlagIsModified
------ READONLY ----- ----- READWRITE --------
Run Code Online (Sandbox Code Playgroud)
这可能只使用XAML吗?
更新:嗯,我通过在容器上设置绑定而不是在容器上修复此情况FlagThingy.但我仍然想知道这是否可行.
我有一个带有索引器属性的类,带有一个字符串键:
public class IndexerProvider {
public object this[string key] {
get
{
return ...
}
set
{
...
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
我使用索引符号绑定到WPF中此类的实例:
<TextBox Text="{Binding [IndexerKeyThingy]}">
Run Code Online (Sandbox Code Playgroud)
这工作正常,但我想PropertyChanged在其中一个索引器值更改时引发事件.我尝试使用属性名称"[keyname]"(即在键的名称周围包括[])来提升它,但这似乎不起作用.我的输出窗口中没有任何绑定错误.
我不能使用CollectionChangedEvent,因为索引不是基于整数的.从技术上讲,该对象无论如何都不是一个集合.
我可以这样做,等等,怎么样?
我想使用Aero文本框样式,但仍覆盖一些属性.我尝试通过以下方式实现此目的
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
但是,这会导致StackOverflowException启动我的应用程序.当我删除对PresentationFramework.Aero的引用时,这可以工作,但我得到了默认的操作系统样式,这使得应用程序很难看.;)
所以,实际上:如果我想在我的所有文本框上覆盖一些样式,我就无法获得Aero外观.如果我想要Aero外观,我无法覆盖任何样式.僵局.
有办法解决这个问题吗?
有没有办法重新定义/别名现有SolidColorBrush(或任何其他资源,实际上)?
举个例子:我在外部ResourceDictionary中有一个画笔,我想用自己的键而不是原始键来引用它.我不想依赖外部参考,因为实际的刷子将来很容易改变.
有没有办法让tabcontrol采取最大标签项的大小(实际上,tabitem的内容)?
由于tabcontrol没有指定特定的大小,因此它应该自动调整大小:它可以正确地执行此操作,但是当您切换选项卡时,它会自动将其自身调整为当前所选选项卡内容的高度(和宽度).
我不希望调整大小发生,让tabcontrol假设最大项目的高度,但仍然让它自动调整大小.
有线索吗?我尝试数据绑定到Height使用多绑定作为内容的每个元素ActualHeight的Items属性,并对Tabcontrol 的属性和属性进行绑定.但是,唉,ActualHeight内容元素总是0.
<TabItem Header="Core" >
<Grid Margin="5">
<Grid.Height>
<MultiBinding Converter="{Converters1:AllTabContentEqualHeightConverter}">
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}"/>
<Binding Path="Items" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type TabControl}}"/>
</MultiBinding>
</Grid.Height>
...
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
我有一个使用数据绑定填充的项目网格.在网格中我有一个DataTemplate特定的细胞.我需要访问DataContext根元素(托管网格的元素),以便我可以访问其他绑定以支持我的datatemplate.
所以你有了:
Window
Window.DataContext = TheDataSourceWithItemsAndSupports
DataGrid.ItemsSource = {Binding Items}
DataTemplate
ListBox.ItemsSource = {Binding Supports}
Run Code Online (Sandbox Code Playgroud)
我希望{Binding Supports}继续TheDataSourceWithItemsAndSupports,但我不知道该怎么做.我试过指定,{Binding}但总是返回null.我也尝试过使用RelativeSource FindAncestor,但产量null也是如此.
有线索吗?
有人知道是否可以在基于IValueConverter的类上进行数据绑定?
我有以下转换器:
[ValueConversion(typeof(int), typeof(Article))]
public class LookupArticleConverter : FrameworkElement, IValueConverter {
public static readonly DependencyProperty ArticlesProperty = DependencyProperty.Register("Articles", typeof(IEnumerable<Article>), typeof(LookupArticleConverter));
public IEnumerable<Article> Articles
{
get { return (IEnumerable<Article>)GetValue(ArticlesProperty); }
set { SetValue(ArticlesProperty, value); }
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
...
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
它的目的是通过Id查找列表中的文章,并返回该文章.
但是,我想通过将一个集合数据绑定到它来填充Articles属性,如下所示:
<local:LookupArticleConverter Articles="{Binding Articles}" x:Key="LookupArticle"/>
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.永远不会调用setter方法.source属性包含一个实际的非空集合,所以这不是问题.
两者都没有关于输出日志中的绑定的错误消息.
有线索吗?
我可能正在寻找错误的方法,但是:
有没有办法通过代码获得绑定的结果值?
可能是明显的东西,但我找不到它.
我正试图找到一种方法来检测视图是否正在动画.
例证:我在视图层上应用了阴影,为性能指定了shadowPath.调整视图大小时,阴影应该生成动画.我可以观察视图的框架,并相应地更改图层的shadowPath.但是当视图调整大小时,阴影会向前跳跃,因为更改不是动画.
我知道如何使用CABasicAnimation为shadowPath设置动画,但我需要知道正在进行的动画的属性,以便我也可以将它们应用到我的动画中(主要是:持续时间,缓动).
这是一个框架类型的组件,所以我不能假设我事先知道持续时间和缓动属性.
有没有办法在观察框架时检测开始/运行动画?
假设我有这个多重绑定:
<MultiBinding Converter="{StaticResource FooBarConverter}>
<Binding Path="Foo" Converter="{StaticResource FooConverter}" />
<Binding Path="Bar" Converter="{StaticResource BarConverter}" />
</MultiBinding>
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用:传递给FooBarConverter 的值数组包含DependencyProperty.UnsetValue每个值(在本例中为两个)。删除子绑定上的转换器(FooConverter和BarConverter)给我实际值。顺便说一句:这些转换器被正确调用,只是看起来它们的结果被丢弃了。
这是有意的行为吗?我想绑定 2 个属性,因为我需要在将它们放入MultiValueConverter...之前至少转换其中之一。
我想为UIColor添加一些类方法.我已经实现了它们,一切都编译得很好,但在运行时我收到以下错误:
因未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'+ [UIColor colorWithHex:]:无法识别的选择器发送到类0x8d1d68'
这是头文件:
@interface UIColor (Hex)
+ (UIColor*) colorWithHex: (NSUInteger) hex;
@end
Run Code Online (Sandbox Code Playgroud)
这是实施:
#import "UIColor+Hex.h"
@implementation UIColor (Hex)
+ (UIColor*) colorWithHex: (NSUInteger) hex {
CGFloat red, green, blue, alpha;
red = ((CGFloat)((hex >> 16) & 0xFF)) / ((CGFloat)0xFF);
green = ((CGFloat)((hex >> 8) & 0xFF)) / ((CGFloat)0xFF);
blue = ((CGFloat)((hex >> 0) & 0xFF)) / ((CGFloat)0xFF);
alpha = hex > 0xFFFFFF ? ((CGFloat)((hex >> 24) & 0xFF)) / ((CGFloat)0xFF) : 1;
return [UIColor colorWithRed: red green:green blue:blue alpha:alpha]; …Run Code Online (Sandbox Code Playgroud) 有没有办法在编译时找出项目路径?
我想创建一个单元测试,测试默认web.config中的配置(项目文件夹中的配置).主要是为了减少人为错误.
我不能在运行时依赖程序集位置(用于测试),因此我需要知道项目文件夹在哪里访问web.config.
我需要一个"通用"解决方案,因为我想为多个项目使用相同(基础)测试代码,并且对于大多数开发机器而言,物理位置无论如何都是不同的.
谢谢.
configuration nunit web-config visual-studio-2008 visual-studio
wpf ×9
data-binding ×5
multibinding ×2
resources ×2
aero ×1
animation ×1
binding ×1
c# ×1
categories ×1
cocoa ×1
height ×1
indexer ×1
ios ×1
iphone ×1
nunit ×1
objective-c ×1
readonly ×1
tabcontrol ×1
web-config ×1
xaml ×1