|
This is a follow-up to an post I made a few days ago that didn't receive any answers. I was asking why events like MouseDown and MouseUp cannot be captured inside FlowDocument containers. Those mouse events don't seem to be generated, and I can't find any explanations either in MSDN or the Microsoft WPF forums explaining why mouse events are thrown away. You'd think they'd explicitly state why this happens. The problem isn't mentioned in any of the several WPF books I also have. When other people ask the same question on other forums, no one really comes up with an answer, not that I've found anyway.
There is one mouse event that is reported, and that is the Click event for UI objects that can listen for that event, such as the Button and Hyperlink elements. These need to be placed inside BlockUIContainers or InlineUIContainers within FlowDocuments. What I was actually trying to do was receive control on a MouseUp event when the user clicked a thumbnail of a screenshot (in the form of an Image element) within a FlowDocument, so that I could bring up another dialog showing the screenshot full size. So one way to get this effect is to put the thumbnail of the screenshot on a button, inviting the user to click the button to get the dialog showing the screenshot full size. That works rather nicely and is a straightforward solution. But an even more attractive option is an inline Hyperlink:
<InlineUIContainer>
<TextBlock>
<Hyperlink
Name="optimal"
Click="optimal_Click"
>
Screenshot
</Hyperlink>
</TextBlock>
</InlineUIContainer>
In any case I think that for some reason, Microsoft is deliberately crippling all elements derived from TextElement (such as Paragraph). All I'm asking for is an explanation for why they do this. Maybe the answer is as simple as, "You should be using Button or Hyperlink within FlowDocuments to do such things." It's actually rather annoying that Microsoft documents all the mouse and preview mouse events for TextElements as if they're all legitimate and yet none of them do anything. Based on the number of Google responses I get when I tried to find out how to get mouse events inside FlowDocuments, the MSDN documentation sure is sending a lot of people on wild goose chases.
modified on Sunday, October 11, 2009 11:26 AM
|
|
|
|
|
They aren't crippling these events. They are capturing them because they have a particular purpose, i.e. they are captured so that you can do things like drag/highlight text, or select paragraphs.
"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
|
|
|
|
|
I also saw your answer to my previous post. So I guess I should have been looking for PreviewMouseLeftButtonDown instead of PreviewMouseLeftButtonUp. The only reason I was looking for Up instead of Down is because I wanted to make it look like a Click event.
My wording, "crippling these events," was probably too extreme, but not totally off base, it seems to me. Pre-empting would perhaps be a better term. Microsoft isn't literally crippling these mouse events, but it is pre-empting them, for selecting text. But now I don't understand why it has to do this. For example, it doesn't do it for the TextBox element. You can select text in a TextBox and drag it somewhere else, and at the same time, capture PreviewMouseLeftButtonUp. I know because I do that all the time.
Maybe there's a good reason for pre-empting these mouse events for the TextElement class. But what is it? I wasn't able to find any MSDN documentation explaining this, and if it is documented somewhere, it must be pretty obscure because I ran into a lot of posts Googling with the same issues I had, with no one giving your answer.
I think pre-empting is a fair description, because if I do capture the Down event to bring up a dialog, that interfers with highlighting (and perhaps dragging) text, even if I don't say e.handled = true . As mentioned above, this isn't true for the much simpler TextBox element.
In any case, after wrestling with various possibilities, I saw that the best way to accomplish what I want is to put a Hyperlink inline in my text and capture its Click event. That looks very clean for the user and doesn't interfere with text highlighting at all. So in the end I got what I want without intercepting any of the mouse events (other than Click).
modified on Sunday, October 11, 2009 8:15 PM
|
|
|
|
|
Hi
I'm having a bit of an issue with my progress bar in WPF. Let me first explain why I want a progress bar. I have a list of products that I save back to a database when clicking a Save button. Sometimes this list can contain quite a lot of items, and this takes a while to save. I use a for loop to loop through and save each item in this list. So what I want to do is increment the progress bar after each loop iteration. Is this possible? Below is what I tried doing but it only updates the progress bar after the loop has finished, even though I'm running it on a different thread:
for (int i = 0; i < someList.Count; i++)<br />
{<br />
<br />
new Thread(delegate()<br />
{<br />
UpdateProgress(100 / productPartsList.Count);<br />
}).Start(); <br />
}
<br />
public void UpdateProgress(double increment)<br />
{<br />
progressIncrement = progressIncrement + increment;<br />
<br />
Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { progressBar1.SetValue(System.Windows.Controls.ProgressBar.ValueProperty, progressIncrement); }, null);<br />
}
Any hints?
|
|
|
|
|
Hi,
I think you have to use another DispatcherPriority flag.
Because : DispatcherPriority.Background means the enumeration value is 4. Operations are processed after all other non-idle operations are completed.
So i would recommend you to use at least DispatcherPriority.Normal or you also could try DispatcherPriority.Render .
Cheers Noodles
|
|
|
|
|
Thanks Noodles. That didn't help though, and I tried every priority available.
Here's another code sample I tried:
NOTE: This is called inside my loop, so it gets done for every loop iteration
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(
delegate()
{
System.Windows.Threading.DispatcherOperation
dispatcherOp = prgbSave.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Render,
new Action(
delegate()
{
progressIncrement = progressIncrement + (100.0 / productPartsList.Count);
prgbSave.Value = progressIncrement;
}
));
dispatcherOp.Completed += new EventHandler(dispatcherOp_Completed);
}
));
thread.Start();
This does the same The progressbar only gets updated after the loop has completed.
|
|
|
|
|
This[^] blog post will show you how to implement a version of DoEvents(), that should help.
|
|
|
|
|
The normal way to do this in a WPF application is to implement a background worker, where you'd save the items in your background thread, and you'd dispatch the updated progress values back to the calling thread which would update the progress bar.
"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
|
|
|
|
|
Hello
I have a textBox which I want to add some "ghost" text on, which is visible whenever the textbox does not have focus.
I could do it with codebehind, but since I am new to WPF and XAML I would like to do it all from XAML code, to get some practice.
Currently my XAML code looks like this:
<TextBox x:Name="textBoxUsername" Margin="5,5">
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsFocused" Value="false">
<Setter Property="Text" Value="Username"/>
<Setter Property="Foreground" Value="LightGray"/>
<Setter Property="FontStyle" Value="Italic"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
What I would like to do, is add another statement to the trigger so
it checks if the text is set by the user.
This is where I need help, I cannot figure out what to write, so
it checks if the text is set by the user or not.
If this is not the right way to solve this, I would be happy to get
an Article/blog/something which describes how to do it
//QzRz
|
|
|
|
|
|
Hello, I have a WPF application which runs in a Window. I would like to change that and have it replace the Windows desktop (this makes sense since the application is a file manager, among other things.).
I need some generic explanation of how to do that because I have no clue if it's possible and how. So far I only understand that I'll probably have to call some Win32 functions. I am imagining something like "take the hwnd H of your wpf window, call GetDesktopWindow() as W, take the parent P of W, and replace H as the child of P". (This is what I seem to understand that I probably have to do, but I may be completely wrong. For example, I may need to implement some COM interfaces or create shell extensions.).
Currently I am browsing the source code of some "shell replacements" like geoshell, but I still can't locate the piece of code which replaces the desktop, and I am not sure this would apply to a WPF application anyway. So, I would be very grateful if somebody pointed at the right direction. Thank you very much for any pointers.
Update :
it looks like I did it with the help of this link[^]. It seems to work. Here is the code (the language is F#):
let tWnd =
let help = Interop.WindowInteropHelper mainWindow
help.Handle
mainWindow.ResizeMode <- ResizeMode.NoResize
mainWindow.WindowStyle <- WindowStyle.None
let mutable pWnd = FindWindow("Progman", null)
pWnd <- FindWindowEx(pWnd, IntPtr.Zero, "SHELLDLL_DefVIew", null)
pWnd <- FindWindowEx(pWnd, IntPtr.Zero, "SysListView32", null)
SetParent(tWnd, pWnd) |> ignore
mainWindow.WindowState <- WindowState.Maximized
modified on Saturday, October 10, 2009 7:47 AM
|
|
|
|
|
Hey All,
I am building a Textbox that will have multiple regular expressions that validate when the control looses focus.
I can get this all to work, but at design time in Expression Blend 3 when I go to set the "Validators" I get and error saying "No types are available for you to add to this collection."
does anyone have any ideas on how I can make this work?
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Hi,
i have RibbonControl.dll, used in my application. but i want to change the base color of this ribbon control. look at this demo project which i have downloaded from codeproject.com itself.
http://www.codeproject.com/KB/WPF/ribboncontrol/ribboncontrol_demo.zip
can any body help me out..
Thanks!
|
|
|
|
|
I want to receive control when the user clicks a Figure which contains an Image inside of a FlowDocumentReader. I thought PreviewMouseLeftButtonUp would be the event to look for, but it doesn't get control when I click on the image. So I tried the MouseLeftButtonUp event, and I don't get control there either. What do I need to do? Here is my XAML:
<Paragraph>
<Figure
Width=".5 content"
Height=".5 content"
>
<BlockUIContainer>
<Image
Name="placeholderSS"
Source="Resource/RemoveUnwantedImagesPage.jpg"
PreviewMouseLeftButtonUp="placeholderSS_PreviewMouseLeftButtonUp"
MouseLeftButtonUp="placeholderSS_PreviewMouseLeftButtonUp"
/>
</BlockUIContainer>
</Figure>
When ...
</Paragraph>
Addendum: I also tried the same events from the Figure and the Paragraph. No dice. I get no MouseLeftButtonUp event from any of the three places.
The following link asks the same question but none of the replies offered a correct answer. One answer just regurgitated my attempt, claiming it works and it doesn't. I wonder why it doesn't seem to be possible?
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8e17d9e5-9fb3-4a86-b685-497de3c60e11/[^]
modified on Friday, October 9, 2009 4:13 PM
|
|
|
|
|
All you need to do is handle the PreviewMouseLeftButtonDown event on the Image and set e.Handled = true; . Then you can handle the MouseLeftButtonUp event the way you want. By handling the event (e.Handled), you ensure that the containing item doesn't capture your events.
"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
|
|
|
|
|
Pete O'Hanlon wrote: All you need to do is handle the PreviewMouseLeftButtonDown event on the Image and set e.Handled = true;. Then you can handle the MouseLeftButtonUp event the way you want. By handling the event (e.Handled), you ensure that the containing item doesn't capture your events.
I don't see why you have to do that. You don't have to do it for the TextBox, which also allows highlighting and dragging the highlighted text. See my reply to your earlier post today for a fuller explanation:
http://www.codeproject.com/Messages/3230555/Re-Why-doesnt-Microsoft-support-the-documented-mou.aspx[^]
|
|
|
|
|
Can we use control properties in windows forms from a user control create in Wpf .and currently we are using user control in windows forms....
|
|
|
|
|
Your title was too long here. There was no need to post the whole question in the title, and the answer is yes - if you're using standard properties.
"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
|
|
|
|
|
sorry first for long title..
I mean to say that if i have 3 controls in user control. den can i access events of that controls in my windows forms
|
|
|
|
|
My app is apparently throwing an exception as a result of databinding. Afterward, changes to the controls don't propagate back to the object model (it's like the run time just throws its hands up and says "to heck with it"). Whatever is happening isn't showing up anywhere. No exception, no stack trace, no debugger output, and it isn't making it to the global exception handler either.
I never thought I'd look back wistfully towards developing client side stuff in javascript, but at least there I could get some idea of what was going on. Is there something special I have to do to get this thing to tell me what is going on? I'm using firefox (I wish I could switch for this project, but I don't want to change my default browser for everything else).
|
|
|
|
|
|
So I got my SSL enabled service and non SSL service (both WCF) running fine on my host.
My site is entirely silverlight and is http://****.com
I can call both services fine and results are correct, but however the secured padlock logo will not show up on browser when I am calling the SSL service.
If the access the site and add the 's' at : https://****.com
The padlock will then show up.
But I do not want the site to be SSL enabled for the entire time. I want it only to be SSL enabled only when customer checks out or login.
Keeping in mind my entire site is one big silverlight app, how do I switch to https or enable the padlock logo only when I need it to?
|
|
|
|
|
Are you sure that need the padlock to show up?
From what you have said, you have secured the call to the service (assuming your endpoints etc. are looking at the https services): e.g.
<endpoint address="https://nigel.company.co.nz/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
- but that is all in the background.
Even though you didn't access/download the Silverlight xap with https it will still be communicating directly with the services over https if they are configured that way.
|
|
|
|
|
Thank you Nigel, and yes the SSL service endpoint is correct and everything is working fine.
I know I am calling the service with SSL enabled and fiddler can see it is SSL, but it is all in the background.
I need to show the padlock because customers (and my client) will only believe they are SSL secured only if the browser tells them.
I could says with a textblock that the login is SSL secured, but the browser isnt showing the padlock and it is dubious to them.
|
|
|
|
|
I know what you mean. I have just been talking to my colleague about the same thing.
The funny thing is that once the xap has been downloaded (via https for example) and is running, whatever the browser says is irrelevant, you can still go ahead and be as un-secure as you like in the background with your service calls (assuming you have the clientaccesspolicy.xml in place).
That's my understanding anyway - I would like to be proved wrong though.
Cheers.
|
|
|
|
|