If there are two prism regions defined in a shell, which one is on top is determined by how these are layed out in the shell one below the other.
<Grid Grid.Row="1" x:Name="_redGrid" >
<ContentControl prism:RegionManager.RegionName="RedRegion" />
</Grid>
<Grid Grid.Row="1" x:Name="_greenGrid">
<ContentControl prism:RegionManager.RegionName="GreenRegion" />
</Grid>
For a simple example, you can take a look at this. It has got a red view and a green view.
When you run, it will look like the following.
Is there a way to change this dynamically? Set the zindex of the prism region at run time?
I have extended the above example with a button, objective here is to click the button and change the top to bottom. You can see this example here.
I could do this in the backend file with brute force as follows.
private void btn1_Click(object sender, RoutedEventArgs e)
{
_mainGrid.Children.Remove(_redGrid);
_mainGrid.Children.Remove(_greenGrid);
if (_toggleRegion)
{
_mainGrid.Children.Add(_redGrid);
_mainGrid.Children.Add(_greenGrid);
}
else
{
_mainGrid.Children.Add(_greenGrid);
_mainGrid.Children.Add(_redGrid);
}
_toggleRegion = !_toggleRegion;
}
Click the button, and now the red is on top.
So whats the best way to do this? Is there a feature in Prism which can accomplish this?
Related
Under the category "limitations of the technology":
I have received the requirement to have a screenshot button in my application that will take a screenshot and launch a printer dialog. Fair enough. My code achieves that. I simply take my window, and use a RenderTargetBitmap to render the window.
However, the requirement now states that it should include all content that is hidden behind scrollbars. Meaning, that in the screenshot the application should look "stretched" in order to eliminate scrollbars, and show all data. For instance in case there is a large list or datagrid, all the data should be visible.
Keeping in mind that WPF might be virtualizing and not rendering things that are not in view, is there any way I can achieve this requirement? Is there a possibility of rendering the visual tree to a seperate infinite space and taking a screenshot there? Something else?
In response to comments:
The screenshot button is on an outer shell that only holds the menu. Inside this shell any of 800+ views can be hosted. These views could contain datagrids, lists, large forms consisting of textboxes... anything. There is no way to tell what is 'inside' without walking the visual tree.
The functionality requested is similar to printing a webpage in your browser to PDF. It will also give you the entire DOM instead of just what you see in the limited view of the browser.
XAML:
<Grid>
<Button
x:Name="btnPrint"
Width="50"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Click="BtnPrint_Click"
Content="Print" />
<ScrollViewer Height="500" HorizontalAlignment="Center">
<Grid x:Name="toPrint">
<!--your code goes here-->
</Grid>
</ScrollViewer>
</Grid>
C#:
private void BtnPrint_Click(object sender, RoutedEventArgs e)
{
var pdialog = new PrintDialog();
if (pdialog.ShowDialog() == true)
{
System.Windows.Size pageSize = new System.Windows.Size { Height = pdialog.PrintableAreaHeight, Width = pdialog.PrintableAreaWidth };
toPrint.Measure(pageSize);
toPrint.UpdateLayout();
pdialog.PrintVisual(toPrint, "Print");
}
}
I'm implementing a templated control, which should work as virtual keyboard button - when you hold it, it displays a popup with additional options to choose.
I've implemented the popup more less in the following way:
<Grid>
<Border>Content</Border>
<Grid x:Name="gPopup" Visibility="Collapsed">
<StackPanel x:Name="spSubItems" Orientation="Horizontal" />
</Grid>
</Grid>
I show the popup by changing visibility to visible and setting negative margins for top and bottom. However, when I do that, and when the popup is actually larger than the control, the control is being resized to match its size - despite fact, that it is not inside:
How can I implement the popup, such that it won't expand the container it's on? And such that the container will still match size of its contents?
Edit: In response to comments and answers
I'm not sure if I'm understood correctly. Here's an image with explanation:
I'd like to keep the original container's size the same after showing the popup. I'm unsure how WrapPanel or DockPanel could help me with that.
The solution is simply to use Popup instead of positioned Grid.
Sample- Create a grid
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<!-- Setting a Rectangle having transparent background which set the
Visibility of popup -->
<Rectangle Name="popupRect" Fill="#80000000" Visibility="Collapsed"/>
<!—Here in the above Code we are just filling the rectangle With the transparent BackGround -->
<!—Creating A Border -->
<Border Name="popupBorder" Background="{StaticResource PhoneChromeBrush}" BorderBrush="Red" BorderThickness="2"
HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed">
<!-- Creating A grid Inside the Border and Rectangle -->
</Grid>
Create event for which popup should appear(for both cancel and appear)-
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
popupRect.Visibility = Visibility.Collapsed;
popupBorder.Visibility = Visibility.Collapsed;
}
private void popupButton_Click(object sender, RoutedEventArgs e)
{
popupRect.Visibility = Visibility.Visible;
popupBorder.Visibility = Visibility.Visible;
}
It will work, I guess.
Like spook says, put your gPopup Grid in a Popup element and show it by opening the popup. This won't affect the main visual tree.
The reason the embedded grid embiggens the border is that the outer grid has to expand to hold pGrid and the border expands to fill the outer grid.
I have the following code:
<Expander Header="Expander" HorizontalAlignment="Left" Margin="64,105,0,0" VerticalAlignment="Top">
<Grid Background="#FFE5E5E5" Width="334">
<Button Content="MyButton" />
</Grid>
</Expander>
Basically I'm trying to make my application load the button only when the expander is expanded by the user. The reason why I'm doing this is that my application will have a number of expanders and each expander will host many UI controls. If I load all at once my application will quickly run out of memory so I want to make expander load its child controls only when the user expands it.
Would setting the visibility to Collapsed on load then visible when user expands do the trick?
Edit: UI Virtualization is not an option here because I need pixel based scrolling (which will be disabled if I turned UI virtualization on).
For simplicity of this example, lets decouple the contents of your expander to a some User control.
<!--MyUserControl will contain: -->
<Grid Background="#FFE5E5E5" Width="334">
<Button Content="MyButton" />
</Grid>
Now you can choose only add that content dynamically:
<Expander Expanded="OnExpanded"/>
private void OnExpanded(object sender, RoutedEventArgs e)
{
var expander = (Expander)sender;
if(expander.IsExpanded)
if (expander.Content == null)
expander.Content = new MyUserControl();
}
My application page contains a WebBrowser. I want to add a GestureListener in order to handle the Flick event. But when Flick on the WebBrowser region, it doesn't work. I have tried many ways to let it work, but I failed. I have also tried to use Manipulation instead, but to no effect.
Could someone tell me how to do or whether there is another solution instead?
Following code is the working solution for the Flick or Hold event on the WebBrowser control.
Try the same, it may help you.
Assuming xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" being present in the phone:PhoneApplicationPage tag.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0" Grid.RowSpan="2">
<phone:WebBrowser x:Name="myWebBrowser" Visibility="Visible" IsScriptEnabled="True" IsHitTestVisible="True" Margin="-12,6,0,6" />
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Flick="GestureListener_Flick" Hold="GestureListener_Hold"></toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
</Grid>
And xaml.cs has functions as follows.
private void GestureListener_Flick(object sender, FlickGestureEventArgs e)
{
MessageBox.Show("Flick");
}
private void GestureListener_Hold(object sender, Microsoft.Phone.Controls.GestureEventArgs e)
{
MessageBox.Show("Hold");
}
I have a xaml with a button like this:
Button.xaml
<Grid x:Name="LayoutRoot" >
<StackPanel >
<Button Content="Button1" Click="Button1_Click" />
</StackPanel >
</Grid>
and Button.xaml.cs:
private void Button1_Click(object sender, RoutedEventArgs e)
{
// Get a instance of ClientOversikt
CustomerView childWindow = m_container.Resolve<CustomerView >();
childWindow.Show();
}
It's working fine. But I want to use Databinding in Button.xaml instead of Click="Button1_Click". How could I do it?
I appreciate all the help
Since you're using Silverlight 4, you can use commands. You bind the Command property of the Button to an instance of ICommand, which will open the child window when executed. Then, when you click on the button, the command will be executed.
This page contains a reasonably good introduction to commanding.