|
I'm going to reply to myself as looking at the code I wrote I'd made an obvious mistake. Note, I still get the same exception but the following code is now used:
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0"
Value="{Binding ElementName=scale, Path=ScalingFactor}"/> and
<Border.Width>
<MultiBinding Converter="{StaticResource widthScaler}"
ConverterParameter="">
<Binding Path="{Binding Duration}" />
<Binding ElementName="scale" Path="ScalingFactor"/>
</MultiBinding>
</Border.Width> Hopefully this is now a little closer to the correct solution! Is it?
Regards,
Ray
|
|
|
|
|
Hi Ray,
Following the exception, this line is bad:
<Binding Path="{Binding Duration}" />
So here you are binding the Path property of a Binding object to the Value stored in the Duration property. You are basically double defining your binding statement. This needs to be:
<Binding Path="Duration" />
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Ok, that makes sense too.
When I run (or indeed the designer does the same). I've now got an exception being fired by the WidthScaler
if ( values.Length != 2 ||
values[0].GetType() != typeof(double) ||
values[1].GetType() != typeof(double) )
{
throw new NotSupportedException("Source values should be a pair of doubles");
} The debugger shows that the first value, Duration, is correct. But the second, is DependancyProperty.UnsetValue . If I remove the throwing of an exception and return null, the WidthScaler (the IMultiValueConverter) doesn't seem to be called again!
Regards,
Ray
|
|
|
|
|
Sorry, your second binding is incorrect also. You have:
<Binding ElementName="scale" Path="ScalingFactor"/>
But "scale" is not a named element, it is a resource. To access it, you need to set the Binding.Source property like so:
<Binding Source="{StaticResource scale}" Path="ScalingFactor"/>
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Great!
The application now runs, but moving the slider doesn't seem to result in the MultiBinding being called again (break-pointing doesn't stop the code).
Regards,
Ray
|
|
|
|
|
Did you update the binding there as well? It has the same problem as before. Make sure to look at the Output window of Visual Studio, that will have any binding errors listed.
Also, make sure the Binding for the slider has Mode=TwoWay.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I've now got this, but it still doesn't look like it works:
Xaml is now:
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0" Value="{Binding Source=scale, Path=ScalingFactor, Mode=TwoWay}"/>
I'd changed the binding in the MultiBinding to:
<Binding Source="{StaticResource scale}" Path="ScalingFactor"/>
Error in Output window is:
System.Windows.Data Error: 35 : BindingExpression path error: 'ScalingFactor' property not found on 'object' ''String' (HashCode=-528916476)'. BindingExpression:Path=ScalingFactor; DataItem='String' (HashCode=-528916476); target element is 'Slider' (Name='scaleSlider'); target property is 'Value' (type 'Double')
I'm sure the error will help, once I understand it!
Regards,
Ray
|
|
|
|
|
The two bindings you just posted are not the same. Compare them carefully (ignoring the fact that Mode is set on one of them though).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Ok, given that they're both working on a source of "scale" and a Path of ScalingFactor (ignoring Mode), that leaves the fact that the second isn't a StaticResource. I'm not certain how to convert between the two markup conventions (although I guess I could expand out the Slider's "Value" element).
I tried this and it doesn't change anything
<Slider x:Name="scaleSlider" Width="100" Minimum="0.5" Maximum="10.0" Value="{Binding Source={StaticResource scale}, Path=ScalingFactor, Mode=TwoWay}"/>
Regards,
Ray
|
|
|
|
|
You still get the same binding error with that change?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry, I noticed that you did not implement INotifyPropertyChanged correct. The parameter being passed needs to be the name of the property that changed, not some random text. Otherwise the system will never know where to look for the changed.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
PERFECT...
that was it.
Thanks a lot Tom, I felt I've learned a lot with your help! Thanks again!
Regards,
Ray
|
|
|
|
|
Hi,
Kindly suggest me how to use a DP as ConverterParameter in Xaml.
Thnx,
Ritesh
|
|
|
|
|
Hi all.
When I open a new window from an Asynchronou CallBack Function, an Exception is thrown.
The Exception is "The calling thread must be STA, because many UI components require this wpf"
If I set ApartmentState of the thread to STA using the code Thread.CurrentThread.SetApartmentState(ApartmentState.STA) it is not working...showing an error Failed to set the specified COM apartment state.
How can I open a new window from different Thread, and modify the controls contents?
Please Help me to solve this problem...
Thanks in Advance
Vayanan
|
|
|
|
|
vayanan wrote: How can I open a new window from different Thread
You can't.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi All,
I've been using RoutedCommand for pretty much all my commanding needs in WPF so far, they are great. However, I have one architectural question.
I want to move a load of my command logic into a different assembly rather than just using a routed command to kick off logic via code in my window code behind I was to off load everything to the other assembly. The problem I have is getting some information from the UI. Say I have an export database to XML routed command the button is hooked up to command bindings in window.xaml. The routed command needs to have a file path and name to export too so if this routed command was in a namespace referenced BY the UI how would I communicate the result of a FileDialog to the routed command logic in the other assembly?
Are there any options other than having the FileDialog.show() in the window.xaml.cs in order to get a file path and name to save to and then kicking off the exporttoXML() method in the datalayer?
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Jammer,
Can you reword the question and trim out the implementation details. Not sure exactly what you need to accomplish.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi Karl,
Say I have a command binding in the UI Exe that kicks off command logic in my datalayer dll. This command also requires a file path + name variable to be passed to it. What's the best way to achieve this whilst keeping ALL the implementation in the datalayer dll (including Executed + CanExecute)?
Is that even possible? Do I have to keep some FileDialog.Show() logic in the UI exe?
Cheers,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
If you want to pass additional information in the Command event args, then derive a class that has the data you need.
You'll need to write a custom command with custom command args. Very easy to do.
However...
Not sure what you are doing here. Typicaly, data layers don't handle Commands or UI interaction like FileDialog.Show. Maybe you want to handle the file selection in the UI and then call a method and pass it the file name?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Jammer - architecturally it's a very bad idea for you to want to put the FileDialog in anything other than the UI - this is where it belongs. Consider the case where you decide that you want to spread the load of your application, and you decide to move your datamodel code onto a server (with the FileDialog code being in the data model); at this point the file dialog will want to run on the server (where there will normally be nobody logged in).
Please rethink this - for your own sanity.
|
|
|
|
|
Thanks for the feedback peeps.
I'm just going a tad mental with the WPF DM-V-VM model that Dan Crevier talks about. Trying to get as much code out of my main window code behind.
Your both bang on the money, i'm being daft!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi All,
I met a problem,my customer feedback that they want the font a bit "bold",but when I changed the font to "Bold",they said that not what they really want. it really make me crazy,but it was what I have to face.
so does anyone have the experience to set the font a bit "bold"? maybe use some font brush...I don't know how to do it.
any suggestion,any idea are welcome!
Robin
|
|
|
|
|
That just sounds insane!!!
Personally this sounds like a red herring scenario. Maybe they are just explaining their point using the wrong language. Have you thought about showing them different options?? Different fonts?? Font sizes??
WPF allows you to embed fonts in applications so you aren't tied to just using system fonts, that said I haven't played with those settings at all. You also get into licencing issues when you start embedding other peoples assets in your application.
Anyway you can:
FontWeight="Medium"
FontWeight="SemiBold"
etc ...
The option that will actually have an effect will depend on the font you are using. Some of these settings with a lot of fonts (particularly system fonts) will have no effect ...
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
I need a custom Canvas control with coordinate system centered in the middle of it and I still don't know, how to implement it using default WPF Canvas. I know, that there are some Transformations, that I can use, bud I didn't managed to use them for acquiring this goal.
All that I need is just Canvas and the ability to add dynamicaly objects like Ellipse, Polyline, etc., but the Left 0 Top 0 position should be in the middle.
Any idea?
|
|
|
|
|