|
As you are aware, it can seem pretty tricky to work out what the location of a control is in WPF space because the margin relates to the parent of the control which may or may not be the window. What you could do is something like this:
private Point GetElementLocation<T>(Window window, T control) where T : UIElement
{
GeneralTransform xform = control.TransformToAncestor(window);
return xform.Transform(new Point(0,0));
} This gives you the co-ordinates of the top-left of the control. From here, it's fairly simple to work out how big a control is by adding the Width and Height in, which gives you the rectangle that represents your control. Now, it's a simple matter to just check the bounds of each control and see if it falls inside your selection rectangle (note that this is a rough test only, as it really only caters for rectangular shapes - it's entirely possible that a circle doesn't fall within the bounds for instance).
Note that an alternative to TransformToAncestor is to use the following:
private Point GetElementLocation<T>(Window window, T control) where T : UIElement
{
Vector vector = VisualTreeHelper.GetOffsetAt(control);
return new Point(vector.X, vector.Y);
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks for this Pete. Off to have a play with this now. What I had up to this point was:
Rect selectionRect = new Rect(_mouseDownPos, mouseUpPos);
foreach (var editor in Editors)
{
var bounds = VisualTreeHelper.GetDescendantBounds(editor);
if (selectionRect.IntersectsWith(bounds))
{
editor.IsSelected = true;
}
else
{
editor.IsSelected = false;
}
}
This is sort of working but it's far from correct at the moment.
Thanks,
|
|
|
|
|
Awesome Pete ... got it licked in no time thanks to your help! Much appreciated chap.
|
|
|
|
|
Glad I could help mate.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi I've been doing WPF for a while now and am unsure of the best way to approach something so am asking here to see if you guys can help.
Basically I want to use a WPF frame to display multiple pages in one window. However I want to edit the existing frame somewhat.
I know there is a Back and Forward button that can be used with the frame, however I would like some more functionality, like for example a Home button. So to my question whould it be best to:
Create a custom control/ user control using the frame for the basica navigation for back & forward
Or Edit the exisiting Frame template and add the extra button creating my own styles for all the buttons Back/Forward and Home. (if possible)
Or Use a frame with out the header and then create seperate buttons on the screen that hock into the navigation of the Frame to do back and forward.
Thank you in advance for you advice on this matter.
Gretna
Some people are like slinky's... They're not really good for anything but they bring a smile to your face when pushed down the stairs
|
|
|
|
|
Hai all ,
Can anyone help me how to print page number in XamReportPreview.
Thank you
|
|
|
|
|
Hello
I'm using CodePlex WPF ComboBox and is having trouble pre-select item
From code behind, I bind the combo box to a DataTable with two columns:
<br />
...<br />
SomeTableSrc = new DataTable("SomeData");<br />
SomeTableSrc.Columns.Add("Data", typeof(string));<br />
SomeTableSrc.Columns.Add("IsSelected", typeof(bool));<br />
lstSomeData.DataContext = SomeTableSrc.DefaultView;<br />
Xaml:
<combobox name="lstSomeData">
<combobox.itemcontainerstyle itemssource="{Binding}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
The above will select relevant "ComboBoxItem" (and it works fine, if you click on ComboBox, as menu expands you can see desired items actually get selected), *** BUT *** "SelectedValue" or "Text" of "ComboBox" (not items) remains blank - and setting these "ComboBox" attributes directly just don't work.
<br />
lstSomeData.SelectedValue = "ABC";<br />
<br />
lstSomeData.Text = "ABC"; <br />
And I've already tried (PreSelectedData = code behind attrib hardcoded to return string "ABC"):
<ComboBox.ItemContainerStyle ItemsSource={Binding} Text="{Binding PreSelectedData}" SelectedValue="{Binding PreSelectedData}">
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
Or even outright hardcode,
<ComboBox.ItemContainerStyle ItemsSource={Binding} Text="ABC" SelectedValue="ABC">
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
No luck!
dev
modified on Wednesday, July 7, 2010 10:23 PM
|
|
|
|
|
I am building a fairly large network of agents and 'mothership' servers.
I'm writing a WPF application which will connect to each mother and either configure/manage/view it's agents.
I can have a large collection of mother's out there.
What I want to do is keep client configurations in the config file.
In the program I want to be able to scan the clients and for each endpoint build up a list of endpoint names.
This way the consumer of the program can select a mother, then run requests against that service.
It looks as if ConfigurationManager.GetSection() might do the trick, but it only returns an object.
Has anyone written code to walk the list of client endpoints to build a list?
Any help appreciated
|
|
|
|
|
Ok I'm trying to see what is missing from my system that seems to be giving problems whilst trying to build this program. The program is Groceries Shopping Helper off of Codeplex.[^]
I made modifications to the main project in the solution but the web product seems to be giving me problems. I found this link: [^] and it helped get the client going but Groceries.web is still showing the following missing:
1) System.Web.DomainServices (According to link should be: System.ServiceModel.DomainServices.Server)
2) System.Web.RIA (System.ServiceModel.DomainServices.Server)
Now when I go in to add a reference I can see System.ServiceModel and System.ServiceModel.Web but none that have DomainServices in their name. This leaves me perplexed, hornswoggled and all those other words as far as what pieces I need to add to my system for this.
I have installed currently Silverlight 4, the Control Toolkit, WCF RIA Services and the WCR RIA Services Toolkit. (Toolkit is May edition, all of these have been installed in the last week).
So any help that anyone can give me will be much appreciated as I'm trying to actually get some things done. LOL.
Thanks Christopher
P.S.: One addendum that may help. I just tried to add a new item and had no entry for ADO.NET Entity Data Model wizard. I am running on Win 7 and using Visual Studio 10 Ultimate.
|
|
|
|
|
Hi All,
Does anyone know of any resource online that talks about this kind of functionality? I'd like to be able to select a range of controls in the UI using the mouse but showing a lasso as the user drags over the UI.
Cheers,
|
|
|
|
|
The first result for lasso.
|
|
|
|
|
Thanks chap, how I missed that I'll never know!
|
|
|
|
|
Hello,
I would like to draw lines and shapes smoothly and dynamically on mouseDown, mouseMove and mouseUp events on a WPF window and would like the behavior to be like this: On mouseDown the drawing procedure starts (The first point is taken), on mouseMove the drawing continues and previous shapes are cleared (The temporary and undecided second point is taken), on mouseUp the last shape is drawn and the procedure is done (The second point is decided). I tried to make a simple code to do that but it didn't look so smooth, I also couldn't clear the shapes already drawn on each mouseMove event. I wonder what is the best way to accomplish this with best performance.
Any help will be appreciated.
|
|
|
|
|
You might want to look at some of the animation styles available - as shown here.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hai all,
I am using XamReportPreview,the printer select dialog shown when the print button is pressed and saved it .
My Problem is when i press the print button second time it does not show the print select dialog.
After close and open the print preview screen the print select dialog is shown .
Can anyone help me how to show the dialog without closing.
|
|
|
|
|
Hi,
How to embed a youtubes videos in my silverlight xaml pages please give me samples.
With regards
Ch.Gayatri
|
|
|
|
|
|
Without web services is this issue will solved, if not then or yes then how.I tried but i did not find the solution.Could any one reply for this solution.
Thanks in Advance
Ch.Gayatri
|
|
|
|
|
Have a look at this[^] thread.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
still i didnt find the solution
|
|
|
|
|
Have you tried anything yet?
What problem are you facing?
See here[^] for another link.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Still did not get the solution while placing the youtube url it not naviagting with the silverlight3 , media player control..If some code sample is there, please post it here.
Thanks in advance
Ch Gayatri
|
|
|
|
|
While giving the you tube urls its not working http://www.youtube.com/watch?v=Tr1qee-bTZI[^], i gave this url in
<Grid x:Name="LayoutRoot" >
<ExpressionMediaPlayer:MediaPlayer Margin="70,57,147,178">
<ExpressionMediaPlayer:MediaPlayer.Playlist>
<ExpressionMediaPlayer:Playlist>
<ExpressionMediaPlayer:Playlist.Items>
<ExpressionMediaPlayer:PlaylistItem
MediaSource="http://www.youtube.com/watch?v=Tr1qee-bTZI"
Title="Star Trek Trailer" VideoHeight="800" VideoWidth="600"/>
</ExpressionMediaPlayer:Playlist.Items>
</ExpressionMediaPlayer:Playlist>
</ExpressionMediaPlayer:MediaPlayer.Playlist>
</ExpressionMediaPlayer:MediaPlayer>
</Grid>
please tell me how to get the videourl from youtube .
Thanks in Advance
Ch Gayatri
|
|
|
|
|
Maybe this [^]can help you.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Even though in my system having Java Version 6 Update 20 , still giving this error the You tube url in http://keepvid.com[^]
Error: Please click here to download Java. If you already have Java, please restart your browser and try again.
It appears you do not have Java installed or it is disabled on your system.
You can get Java here.
If you are still having difficulty with Java, check here for installing Java, or here for detailed instructions on enabling Java in your browser.
For an ad-free version of Keepvid, please support us by using the KeepVid program to download videos.
Whts is the solution.
Thanks and regards
Ch Gayatri
|
|
|
|