|
Visibility is an enum, and not a bool; as your XAML implies.
And I use all 3; so a binary converter is useless.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The converter returns Collapsed or Visible, the only 2 states I need. The converter works perfectly for a command button but not for a groupbox, the issue is in the groupbox control.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It looks like it should work, assuming your converter is returning the correct values.
Are there any binding errors in the Visual Studio output window?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The VM grew too complex so instead I split it along the lines of the visibility requirement which is logical and happens to eliminate this issue nicely.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a wizard. When page 1 is reached I get a UserControl from a list of MEF plugins and add it to the page.
The UserControl has a DP called IsValid on it. I want to bind this property to a property on the VM called IsDatabaseValid
Here's what I have
private void NextExecuted()
{
CurrentPage = CurrentPage + 1;
DatabaseSelectorControl = null;
IDatabase control = null;
switch (CurrentPage)
{
case 0:
break;
case 1:
control = ((App)Application.Current).DatabaseService.DBPlugins
.Where(x => x is UserControl && x.DatabaseType == SelectedDatabaseType.DatabaseType).FirstOrDefault();
DatabaseSelectorControl = (DatabaseSelectorBase)control;
break;
}
if (DatabaseSelectorControl != null)
{
Binding binding = new Binding();
binding.Source = this;
binding.Path = new PropertyPath("IsDatabaseValid");
binding.Mode = BindingMode.TwoWay;
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
BindingOperations.SetBinding(???, DatabaseSelectorControl.IsValid, binding);
}
}
How do I create this binding?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
It should be as simple as:
BindingOperations.SetBinding(DatabaseSelectorControl, DatabaseSelectorControl.IsValidProperty, binding);
NB: Assuming DatabaseSelectorBase inherits from UserControl , you can simplify the LINQ statement that finds the control to:
DatabaseSelectorControl = ((App)Application.Current).DatabaseService.DBPlugins
.OfType<DatabaseSelectorBase>()
.FirstOrDefault(x => x.DatabaseType == SelectedDatabaseType.DatabaseType);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The only change I needed was this
BindingOperations.SetBinding(DatabaseSelectorControl, DatabaseSelectorControl.IsValidProperty, binding);
to this
BindingOperations.SetBinding(DatabaseSelectorControl, DatabaseSelectorBase.IsValidProperty, binding);
to this
"DatabaseSelectorBase" is the control where "DatabaseSelectorControl" is an instance.
Thansk for both tips. Worked great.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Your Path doesn't have a Fill.
This space for rent
|
|
|
|
|
Sorry, I figured it out
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
There was no need to delete your question. Now, anyone else who is facing a similar issue won't have the context.
This space for rent
|
|
|
|
|
I have more of a win forms background and while it is quiet at work thought I'd have a look at WPF.
Does anyone have a good place / reference that I could use for UI design?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Go to the WPF section in CodeProject articles, and look at all those by Sascha Barber; some really excellent materials.
|
|
|
|
|
I find Sasha's article to be over the top for an introduction to a subject. I'd look for an introductory article, one that concentrates on the MVVM concepts.
You also need to pick a framework to use, I use GalaSoft MVVM Light because it is a minimalist framework, but there are many other options out there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft.
it makes sense to look at an MVVM framework first, as I knew that this was a large part of the WPF concept that I would need to understand.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I am working on a tool that allows the user to design a piece of equipment. The designer will be very much like this
One important thing will be the ability of the user to design their own shapes. In the example I posted the shapes are pre-designed. But in this case the user would need to be able to free hand draw a shape that can then be dragged onto the design surface.
Any thoughts on how to do this?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
2D or 3D?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Sorry, 2D
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
For 2D, a "connect the dots" (see WPF "Path") method can help with free-hand drawing.
Or, you can use "small" shapes to create bigger shapes; usually using fractals.
Depends on how complicated the shapes are.
An Introduction to Fractals
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 24-Aug-17 11:58am.
|
|
|
|
|
I guess the thing I would really want it to be able to detect when the user has clicked inside a custom drawn control.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
While my user controls may not have "click" events, they can respond to "preview mouse down" which "act" like click handlers or context menu popups (to the user).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Right, but how do you know if the user clicked inside the shape? If I had a user control, which is square or rectangular, and I draw a triangle or star on it, I would want to only handle the mouse down if it's actually inside the shape I've drawn.
I guess you could evaluate the current mouse position and see if it falls within the path, but that seems rather complex.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
My "shape" would be an "object", that you "shape"; not something I could "click through" in that case.
(If I didn't want to resort to "hit-point" calculations; and I don't).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: (If I didn't want to resort to "hit-point" calculations; and I don't).
My point exactly
So how do you create an object that has an irregular shape?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Here's an idea..
Create a Shape Designer app similar to Blend but MUCH more simple. The user can create basic shapes - Lines, Polygon, Rectangle, Ellipse, etc. This app then saves the path data to a meta-data file that my designer uses to load a toolbox.
Tn my resources I would have
<Style x:Key="BaseShapeStyle"
TargetType="Shape">
;Setter Property="Cursor" Value="Hand" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="Stroke" Value="{Binding Stroke}" />
<Setter Property="StrokeThickness" Value="{Binding StrokeThickness}" />
<Setter Property="Fill" Value="{Binding Fill}" />
</Style>
<Style x:Key="EllipseStyle"
TargetType="{x:Type Ellipse}"
BasedOn="{StaticResource BaseShapeStyle}">
<Setter Property="Height" Value="{Binding Height}" />
<Setter Property="Width" Value="{Binding Width}" />
</Style>
Then in a user control I would have:
<Ellipse Style="{DynamicResource EllipseStyle}"
ToolTip="{Binding ElectrodeDisplayText}"
MouseLeftButtonDown="Ellipse_MouseLeftButtonDown"
MouseLeftButtonUp="Ellipse_MouseLeftButtonUp"
MouseMove="Ellipse_MouseMove"/>
So this way the basic shapes could all have their data saved and re-bound at runtime, and the UI pieces are very small.
By using the basic shapes and some grouping the user could create pretty much anything they wanted.
What do you think?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Yes; that's building up from "smaller" shapes. Still too "big" for me; and I have to build the "starter set".
As I said, use WPF Path commands.
It uses co-ordinates.
You click, you have a co-ordinate and a point.
You can now drag the point.
You draw a line back to the last point.
Etc.
Let the user do the work; all of it.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|