wpf stackpanellwpf stackpanel...

Hi all, I am new to WPF. I have created two stackpanels . In first stackpanel I have created few HyperLink controls. I want the hyperlink to open the new xaml page in second hyperlink. But I am unable to achieve it. suppose I click on &Build Trimmer& hyperlink from left side stackpanel, it should open the xaml file in second stackpane( right side stackpanel).The name of the second Stackpanel is &contentpanel&. I have used the below code but its not
&TextBlock FontSize=&25&&
&Hyperlink NavigateUri=&Page1.xaml#contentpanel& &Build Trimmer &/Hyperlink&
&/TextBlock&
&TextBlock FontSize=&25&&
&Hyperlink NavigateUri=&Page1.xaml#contentpanel& &ISO Generator &/Hyperlink&
&/TextBlock&
&TextBlock FontSize=&25&&
&Hyperlink NavigateUri=&Page1.xaml#contentpanel& &Upload &/Hyperlink&
&/TextBlock&
&TextBlock FontSize=&25&&
&Hyperlink NavigateUri=&Page1.xaml#contentpanel& &Help &/Hyperlink&
&/TextBlock& Please help me with this. Thanks,
Advertisement
Hello Vishwajeet,
The following thing did work:
Hyperlink NavigateUri=&Page1.xaml#contentpanel&
For example,if you code like the following:
&Page x:Class=&WPFBrowserNavigate.Page1&
xmlns=&/winfx/2006/xaml/presentation&
xmlns:x=&/winfx/2006/xaml&
xmlns:mc=&http://schemas.openxmlformats.org/markup-compatibility/2006&
xmlns:d=&/expression/blend/2008&
mc:Ignorable=&d&
d:DesignHeight=&311.638& d:DesignWidth=&572.845&
Title=&Page1&&
&Grid.ColumnDefinitions&
&ColumnDefinition&&/ColumnDefinition&
&ColumnDefinition&&/ColumnDefinition&
&/Grid.ColumnDefinitions&
&Grid.RowDefinitions&
&RowDefinition/&
&RowDefinition/&
&RowDefinition/&
&RowDefinition/&
&/Grid.RowDefinitions&
&TextBlock Grid.Row=&0& FontSize=&25&&
&Hyperlink NavigateUri=&Page1.xaml#textbox1& &Build Trimmer &/Hyperlink&
&/TextBlock&
&TextBlock Grid.Row=&1& FontSize=&25&&
&Hyperlink NavigateUri=&& &ISO Generator &/Hyperlink&
&/TextBlock&
&TextBlock Grid.Row=&2& FontSize=&25&&
&Hyperlink NavigateUri=&Page2.xaml#textbox2& &Upload &/Hyperlink&
&/TextBlock&
&TextBlock Grid.Row=&3& FontSize=&25&&
&Hyperlink NavigateUri=&Page2.xaml#contentpanel& &Help &/Hyperlink&
&/TextBlock&
&StackPanel Name=&contentpanel& Grid.Column=&1& Grid.RowSpan=&4&&
&TextBox Name=&textbox1&&12345&/TextBox&
&/StackPanel&
&Page x:Class=&WPFBrowserNavigate.Page2&
xmlns=&/winfx/2006/xaml/presentation&
xmlns:x=&/winfx/2006/xaml&
xmlns:mc=&http://schemas.openxmlformats.org/markup-compatibility/2006&
xmlns:d=&/expression/blend/2008&
mc:Ignorable=&d&
d:DesignHeight=&300& d:DesignWidth=&300&
Title=&Page2&&
&Grid.RowDefinitions&
&RowDefinition&&/RowDefinition&
&RowDefinition&&/RowDefinition&
&/Grid.RowDefinitions&
&TextBox Name=&textbox1& Grid.Row=&0&&1&/TextBox&
&TextBox Name=&textbox2& Grid.Row=&1&&2&/TextBox&
You can see it will redirect you to the right page. That is how NavigateUri works, navigate to a element container page.
But here you are on the same page so navigate direct you to current page. Would you mind to tell us what do you want to show on your right stackpanel?
Best regards,&
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
HERE to participate the survey.Adding components to StackPane : StackPane&&&JavaFX&&&JavaAdding components to StackPane
import javafx.application.A
import javafx.scene.S
import javafx.scene.control.B
import javafx.scene.control.L
import javafx.scene.layout.StackP
import javafx.stage.S
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
public void start(Stage primaryStage) {
primaryStage.setTitle("BorderPane Test");
//Creating StackPane
StackPane sp = new StackPane();
Label lbl = new Label("JavaFX 2 StackPane");
sp.getChildren().add(lbl);
Button btn = new Button("Button");
sp.getChildren().add(btn);
//Adding StackPane to the scene
Scene scene = new Scene(sp,300,200);
primaryStage.setScene(scene);
primaryStage.show();
Related examples in the same category1.2.3.4.5.6.
&|&Email:info &|&& Demo Source and Support. All rights reserved.WPF Tips and Tricks Part 2 – Panels
Hello Everyone!
First of all, Happy Thanksgiving!  I hope everyone is having a good time and enjoying the holidays.
So it’s been awhile since I started my WPF Tips and Tricks segment and figured it was long overdue for the second installment.  In this part we will look a little bit at Panels and what we need to think about when choosing how we will lay out our forms.
So the primary tip when regarding Panels is that Panels are the “only” visuals in WPF that actually perform any sort of measurement and arrangement calculations.  What this means is that when we create a TextBox and set its Width to 100, the TextBox does not actually draw
the Panel it is contained in will see that it has a TextBox as a child and that its width is 100.  The Panel will then determine where the TextBox needs to be placed inside of itself and if it has enough space to include a width value of 100 and will perform the drawing.
The next tip is thinking of performance.  Lets look at some code to put this into more perspective.
I have created this example layout in 2 different panel formats:
Here is the XAML for the first layout that uses a total of 4 StackPanels:
&StackPanel HorizontalAlignment=&Left&&
&StackPanel Orientation=&Horizontal& HorizontalAlignment=&Right&&
&TextBlock Text=&Field 1: & VerticalAlignment=&Center&/&
&TextBox Width=&100&/&
&/StackPanel&
&StackPanel Orientation=&Horizontal& HorizontalAlignment=&Right&&
&TextBlock Text=&Field 2: & VerticalAlignment=&Center&/&
&TextBox Width=&100&/&
&/StackPanel&
&StackPanel Orientation=&Horizontal& HorizontalAlignment=&Right&&
&TextBlock Text=&Longer Field 3: & VerticalAlignment=&Center&/&
&TextBox Width=&100&/&
&/StackPanel&
&/StackPanel&
Having 4 StackPanels means we have 4 different processes to run measurement and arrangement.  The first StackPanel performs measure when it gets to its first child, that StackPanel will call measurement and arrangement on its children and return up to the first StackPanel. The first StackPanel will then iterate to its second child which performs another set of measurement and arrangement calculations and so on for each StackPanel  child  – causing 4 calculations.  In more complex scenarios this will not be be very performant.
Now lets look at the second, more performant way to lay out this form:
&Grid.ColumnDefinitions&
&ColumnDefinition Width=&Auto&/&
&ColumnDefinition Width=&100&/&
&/Grid.ColumnDefinitions&
&Grid.RowDefinitions&
&RowDefinition Height=&Auto&/&
&RowDefinition Height=&Auto&/&
&RowDefinition Height=&Auto&/&
&/Grid.RowDefinitions&
&TextBlock Text=&Field 1: &
Grid.Column=&0&
Grid.Row=&0&
HorizontalAlignment=&Right&
VerticalAlignment=&Center&/&
&TextBox Grid.Column=&1&
Grid.Row=&0&/&
&TextBlock Text=&Field 2: &
Grid.Column=&0&
Grid.Row=&1&
HorizontalAlignment=&Right&
VerticalAlignment=&Center&/&
&TextBox Grid.Column=&1&
Grid.Row=&1&/&
&TextBlock Text=&Longer Field 3: &
Grid.Column=&0&
Grid.Row=&2&
HorizontalAlignment=&Right&
VerticalAlignment=&Center&/&
&TextBox Grid.Column=&1&
Grid.Row=&2&/&
With this format we have a lot more XAML to write, but we get a much more performant way to lay out the exact same visual content.  We this panel will perform one set of measurement and arrangement calculations.
So looking at it all: the tip here is to really think about performance when dealing with Panels.  The least amount of Panels we can use (as long as we can meet the form requirements), the more performant our WPF applications will be.
I hope you enjoy this and look forward to WPF Tips and Tricks Part 3!
This entry was posted on November 26,
am and is filed under . You can follow any responses to this entry through .
Both comments and pings are currently closed.
Comments are closed.

参考资料

 

随机推荐