|
I have an xbap application and I would like to hide controls on the page during runtime depending on whether the control is flaged as hidden in an Application hidden field table. Can someone tell me the equivance of reading controls on a page. Below is sample code that I used to read controls on a form before WPF.
private void HideControls()
{
foreach (Control c in Controls)
{
if (c.Controls.Count > 0)
{
}
else
{
if (c.Visible)
{
foreach (BUI.ApplicationHiddenField d in ApplicationHiddenFieldCollection)
{
if (d.Field.ToLower().Equals(c.Name.ToLower())) c.Visible = false;
}
}
}
}
}
Thanks
Jonso
|
|
|
|
|
There are several ways to do this.
The best way, is to DataBind the Visiblity property on the control, to a Boolean field on the data that has the value.
You can expose your Application Hidden Field Table as a property on the Window or UserControl, and have the controls in the UI Bind to that property.
You will need to use the BooleanToVisibilityConverter in your binding expression.
By data binding to the Visibility property of the control, you can change the data and the control will collapse, hide or display itself without any additional code.
Just ensure that your data class implements the System.ComponentModel.INotifyPropertyChanged interface.
Another way, not necessarily the best is to walk the VisualTree and set your controls. But I would not recommend this.
If you are knew to WPF data binding, search here on Code Project and the Internet for great tutorials and articles. My blog link below also has a good deal of data binding and links to other great blogs.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Karl Shifflett wrote: the BooleanToVisibilityConverter
OMG. The very first two value converters I wrote (and still use)
were VisibilityToBoolHideConverter and VisibilityToBoolCollapseConverter...
I had no idea that class existed LOL How many other converters are available?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark,
I know there are more in 3.5 and ... I'll try and look them up next week at work.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Looks like 3 or 4 of them in the System.Windows.Controls Namespace,
depending on which documentation is used.
Doesn't look like I've invented any other wheels.
Thanks Karl.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
Are there any anti-alias effects in WPF ?
If so, How can we use it ?
Thanks
|
|
|
|
|
In WPF, text is anti-aliased by default.. One cannot disable this.
|
|
|
|
|
Thanks elektrowolf.
elektrowolf wrote: In WPF, text is anti-aliased by default.. One cannot disable this.
What about Rectangle ? Can we apply it on a shape.
|
|
|
|
|
Does anyone know a good WPF chart component (.NET 3.0) ?
Johan Lombaard
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former - Albert Einstein
|
|
|
|
|
|
Infragistics chart is REALLY good ...
|
|
|
|
|
Hi,
I have developed an animation application in WPF using DoubleAnimationUsingPath, simply i want to display the coordinates (Canvas.Top, Canvas.Left) of shape (say a rectangle shape) which gets continously updated while animating on the PathGeometry (say a ellipse using ArcSegment). I have used following XAML code for Creating Path geometry & then animating a rectangle on that path geometry:
<Grid.Resources>
<PathGeometry x:Key="animPath">
<PathFigure StartPoint="160,170" IsClosed="True">
<ArcSegment Point="140,175" Size="80,180"
SweepDirection="Clockwise" IsLargeArc="True" />
</PathFigure>
</PathGeometry>
</Grid.Resources>
.......
<Path Stroke="Black" x:Name="mainUI" >
<Path.Data>
<RectangleGeometry x:Name="rect00" Rect="0, 0, 60, 60" RadiusX="10" RadiusY="10"></RectangleGeometry>
</Path.Data>
<Path.Triggers>
<EventTrigger RoutedEvent="Line.Loaded">
<BeginStoryboard Name="change1">
<Storyboard>
<DoubleAnimationUsingPath Source="X"
RepeatBehavior="Forever" Duration="0 :15"
Storyboard.TargetProperty="(Canvas.Left)"
PathGeometry="{StaticResource animPath}" />
<DoubleAnimationUsingPath Source="Y"
RepeatBehavior="Forever" Duration="0 :15"
Storyboard.TargetProperty="(Canvas.Top)"
PathGeometry="{StaticResource animPath}" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
...
Here I want to print on console the Canvas.Left & Canvas.Top property of Path when the animation has started and its gets continuosly changed everytime the Path changes its position on the PathGeometry as mentioned in DoubleGeometryUsingPath tag.
Hope you understood the query..
Thanks,
Suyesh.
|
|
|
|
|
|
Great stuff Karl. Just commented on it.
|
|
|
|
|
Hi again!
I created a usercontrol with a view virtual methods so I could derive from them and use the standard behaviour where needed.
Now XAML tells me
"Error 1 Partial declarations of 'xxx.View.UserControl1' must not specify different base classes ...\View\UserControl1.xaml.cs 20 26"
Isn't it possible to do it this way? I do use interfaces but wanted to have a predifined behaviour which can be overwritten where needed.
Help would be appreciated!
Thank you in advance
|
|
|
|
|
Oh dear - you've hit a fairly common problem here, and it's to do with the way WPF generates a backing class to actually map your controls in (it's called xxxx.g.cs where xxx is your class). You need to do a bit of work to get round this, and here's[^] a link to an entry you might find useful.
|
|
|
|
|
An answer as fast as lightning!
Thank you for the tip!
|
|
|
|
|
Anybody knows a better way of displaying a 2D text using ModelVisual3D in WPF?
I have used TextBlock, Glyphs and FormattedText but wanted to see if there is a better way to do the same task.
Thanks,
|
|
|
|
|
I normally use a TextBlock inside a <Viewport2DVisual3D.Visual> . For instance:
<Viewport2DVisual3D ...>
<Viewport2DVisual3D.Visual>
<TextBlock Text="This is my text" />
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
|
|
|
|
|
I have 30-40 TextBlocks to display in a grid. When I rotate the grid I need to update the position of these TextBlocks. It takes almost 98-100% CPU time to render 30-40 TextBlocks.
|
|
|
|
|
A rant:
I have been learning WPF and seem to be getting on OK with it other than its extremely steep learning curve and its let's have 30 lines of code where 1 used to do but one thing which is stopping me actually using it in anger is what sort of PCs does it need to run?
On my development PC (dual core / 2GB of RAM) everything runs extremely slowly - I can't run a lot of the more whizzy samples on here (they run but take an age to render and I have to kill them)
Most of my clients have machines which are well below the spec of my dev machine so why would I write WPF apps if they are unable to run it - I certainly couldn't use WPF for anything other than the most basic apps so why bother using it all?
I know if I scrap it and continue with Windows Forms I will soon forget the little WPF I have managed to scrape together but without a good reason for using WPF (ie people can run the apps) then there doesn't seem much point continuing with it.
|
|
|
|
|
Something does not sound right. What sort of applications are you referring to?
I've been doing WPF development since April of 2007 on many computers and laptops with various hardware and have never had an issue.
I have run and developed WPF on XP with 1 GB memory and Pent4 processor with no issues at all.
Granted, rendering 10 spinning bouncing balls in 3D, may start to slow things down a bit, but other than that no performance issues at all.
Also, Visual Studio 2008 SP1, .NET 3.5 SP1 provides very good performance gains in a lot of areas.
Keep at this. WPF is fantastic (yes, a huge learning curve). You'll be glad you did.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
A lot of the whizzier samples on here don't run (or run extremely slowly) on my PC - I hate to pick on Sacha because I have learned a huge amount from his work but my PC really struggles showing some of his WPF samples - the screensaver and the post it notes samples for example.
However, I have noticed just putting together some WPF versions of part of the apps I work on shows a huge performance slowdown.
Here's a link to a small description of my main app
http://www.divelements.com/net/corporate/casestudies/logicbox.aspx[^]
The grid you see in the screen shot is from Xceed - trying to replicate it using the WPF Xceed grid (admittedly the free version for now) means the grid is at least 10 times slower to display and sort etc.
I don't even know how to start putting together a WPF version of the logic screen you see in that screenshot.
I probably will keep trying with WPF I think I just needed to vent. I am the sole developer here and people are getting fed up of me talking what they consider gibberish to them
|
|
|
|
|
Hmmm - sounds like you are having rendering issues, and this is based on the graphics processor. What type of graphics card have you got in there?
|
|
|
|
|
Graphics card is a NVIDIA Qaudro NVS 285 with 1GB of RAM
|
|
|
|