ivalueconverter

Converter With Multiple Parameters

我的梦境 提交于 2019-11-27 11:03:46
问题 How does one use a converter with Multiple parameters in a Windows Phone 7 Application? 回答1: Converters always implement IValueConverter. That means a call to Convert or ConvertBack passes a single additional parameter. That parameter is extracted from the XAML. As Hitesh Patel suggests there is nothing to stop you putting more than one value into the parameter, so long as you have a delimiter to separate them out later, but you cannot use a comma as that delimits the XAML! e.g. XAML

WPF BooleanToVisibilityConverter that converts to Hidden instead of Collapsed when false?

眉间皱痕 提交于 2019-11-27 09:57:46
问题 Is there a way to use the existing WPF BooleanToVisibilityConverter converter but have False values convert to Hidden instead of the default Collapsed, or should I just write my own? I'm on a project where it's tremendous overhead to do something simple like this (shared stuff goes into a separate solution, and the rebuild/checkin/merge process is an overgrown mutated behemoth of a process), so I'd prefer if I could just pass a parameter to the existing one than to jump through the hoops just

Moq + Unit Testing - System.Reflection.TargetParameterCountException: Parameter count mismatch

三世轮回 提交于 2019-11-27 05:13:47
I'm tring to use a lambda with a multiple-params function but Moq throws this exception at runtime when I attempt to call the mock.Object.Convert(value, null, null, null); line. System.Reflection.TargetParameterCountException: Parameter count mismatch The code is: var mock = new Mock<IValueConverter>(); mock.Setup(conv => conv.Convert(It.IsAny<Object>(), It.IsAny<Type>(), It.IsAny<Object>(), It.IsAny<CultureInfo>())).Returns((Int32 num) => num + 5); var value = 5; var expected = 10; var actual = mock.Object.Convert(value, null, null, null); What is the proper way to implement it? Erik Dietrich

How can you bind to a DynamicResource so you can use a Converter or StringFormat, etc.? (Revision 4)

萝らか妹 提交于 2019-11-27 03:42:15
Note: This is a revision of an earlier design that had the limitation of not being usable in a style, negating its effectiveness quite a bit. However, this new version now works with styles , essentially letting you use it anywhere you can use a binding or a dynamic resource and get the expected results, making it immensely more useful. Technically, this isn't a question. It's a post showing a way I found to easily use converters with a DynamicResource as the source, but in order to follow s/o's best practices, I'm posting it as a question/answer pair. So check out my answer below on a way I

WPF MVVM Radio buttons on ItemsControl

青春壹個敷衍的年華 提交于 2019-11-27 01:19:06
问题 I've bound enums to radio buttons before, and I generally understand how it works. I used the alternate implementation from this question: How to bind RadioButtons to an enum? Instead of enumerations, I'd like to generate a runtime-enumerated set of a custom type and present those as a set of radio buttons. I have gotten a view working against a runtime-enumerated set with a ListView , binding to the ItemsSource and SelectedItem properties, so my ViewModel is hooked up correctly. Now I am

Use IValueConverter with DynamicResource?

こ雲淡風輕ζ 提交于 2019-11-26 20:16:57
问题 Is there a way to define a converter when using the DynamicResource extension? Something in the lines of <RowDefinition Height="{Binding Source={DynamicResource someHeight}, Converter={StaticResource gridLengthConverter}}" /> which unfortunately gives me the following excpetion: A 'DynamicResourceExtension' cannot be set on the 'Source' property of type 'Binding'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject. 回答1: I know i am really late to this

Is there a way to chain multiple value converters in XAML?

心已入冬 提交于 2019-11-26 18:54:04
问题 I've got a situation in which I need to show an integer value, bound to a property on my data context, after putting it through two separate conversions: Reverse the value within a range (e.g. range is 1 to 100; value in datacontext is 90; user sees value of 10) convert the number to a string I realise I could do both steps by creating my own converter (that implements IValueConverter). However, I've already got a separate value converter that does just the first step, and the second step is

Moq + Unit Testing - System.Reflection.TargetParameterCountException: Parameter count mismatch

不问归期 提交于 2019-11-26 11:28:47
问题 I\'m tring to use a lambda with a multiple-params function but Moq throws this exception at runtime when I attempt to call the mock.Object.Convert(value, null, null, null); line. System.Reflection.TargetParameterCountException: Parameter count mismatch The code is: var mock = new Mock<IValueConverter>(); mock.Setup(conv => conv.Convert(It.IsAny<Object>(), It.IsAny<Type>(), It.IsAny<Object>(), It.IsAny<CultureInfo>())).Returns((Int32 num) => num + 5); var value = 5; var expected = 10; var