Control's left and control's Top in WPF
-
2012年7月11日 19:07
Hello everyone,
I have a requirement where i need to show a small wpf borderless window right below a text box ( just like a drop down list open up ).In short, i am trying to set the placement target for the new window to show up at the bottom of the textbox.
Any suggestions ? Moreover TransformToAncestor method didn't help me much.
Thanks,
BR,
JollyWagoner
すべての返信
-
2012年7月12日 0:51
Try using a popup and align it to the parent control with PlacementTarget:
<TextBox Name="myTextBox" Text="My Textbox" HorizontalAlignment="Left" VerticalAlignment="Top"/> <Popup IsOpen="True" PlacementTarget="{Binding ElementName=myTextBox}" > <ContentControl> <Border Background="White" > <Label>The Popup</Label> </Border> </ContentControl> </Popup>
- 編集済み Myndale 2012年7月12日 0:52
- 編集済み Myndale 2012年7月12日 0:52
- 編集済み Myndale 2012年7月12日 0:53
- 回答の候補に設定 Sheldon _XiaoModerator 2012年7月13日 5:05
- 回答としてマーク Sheldon _XiaoModerator 2012年7月20日 8:02
- 回答としてマークされていない JollyWagoner 2012年7月25日 14:53
- 回答としてマーク Sheldon _XiaoModerator 2012年7月30日 3:01
-
2012年7月25日 14:55
Hello everyone,
I forgot to mention but its strictly a window and not popup control that i want to use, otherwise i would have already used it.The popup is limited in the sense that "stays above everything in the world" as long as it remains open.Which is potentially a drawback as everything ( i.e window , error dialog ) that opens up is behind the popup all the time.
Thanks,
BR,
JollyWagoner
-
2012年7月25日 23:04
Hello Jolly.
You could try something like the following...
private void myTextBlock_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Point p1 = myTextBlock.TranslatePoint(new Point(0,0), this); Point p2 = myTextBlock.PointFromScreen(p1); double a = myTextBlock.Height + 10; //You may want to play around with the + 10 margin. Window1 win = new Window1(); win.Top = (p2.Y * -1) + a; win.Left = p2.X * -1; win.Show(); }~Christine
P.S. Sorry my sample used a TextBlock instead of TextBox, but same concept.
- 編集済み Christine L. _ 2012年7月25日 23:05
- 回答の候補に設定 Grecian Developer 2012年7月26日 1:35
- 回答としてマーク Min ZhuMicrosoft Contingent Staff, Moderator 2012年7月30日 2:16
-
2012年7月26日 1:44
Hi
One little improval:
Use "a = myTextBlock.ActualHeight + 10";
If you choose "Height" and there is no explicit value for height
on the element, "a" becomes "double.NaN" and also win.Top.
In consequence there is no valid placement for the window
and the os will position it somewhere arbitrarily on the screen.
Chris- 回答としてマーク Min ZhuMicrosoft Contingent Staff, Moderator 2012年7月30日 2:16
-
2012年7月30日 4:15モデレータ
Hi JollyWagoner,
I think your issue has been resolved, so I will mark your thread as "Answered", if you need further help, please let me know.
Best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

