I am using following code to set gray light effect on window when I open a popup. It works fine but it basically reloads all controls or refreshes the main window .
Especially this line: currentWindow.Content = lightboxGrid;
Window currentWindow = Application.Current.Windows.Cast<Window>()
.SingleOrDefault(x => x.Name.Equals(MAIN_WINDOW_NAME));
Grid lightboxGrid = new Grid();
object currentWindowContent = currentWindow.Content;
currentWindow.Content = null;
lightboxGrid.Children.Add(new ContentControl()
{
Content = currentWindowContent
});
// now add the grid that will "black out" the content
Grid blackoutGrid = new Grid();
blackoutGrid.Background = new SolidColorBrush(Colors.Black);
lightboxGrid.Children.Add(blackoutGrid);
blackoutGrid.Opacity = 0.0; // start fully transparent
blackoutGrid.Loaded += blackoutGrid_Loaded;
currentWindow.Content = lightboxGrid;
this._lightboxEffectApplied = true;
What could be the option to have the same effect without refreshing the main window or reloading the controls?
If your main window has a Grid as its layout root (even if all the content is in the first cell), then you could add this blackoutGrid as a child to that grid and it will display above the other elements without messing with the original visual tree structure.
In this case, the Content of your Window would be a Grid, and you would add your blackoutGrid to that Grid, and remove it when you are done.
The way you are writing this seems to be a little against object-oriented practice. Technically it should be your Main Window that has the ability to display a lightbox effect.
Related
I'm trying to create a container with a sizable number ( > 20 or a number that exceeds the screen height) of items as a scrollable list using BoxLayout, it works (ie you can see the content moving up and down when one swipes) but trying to view items at the bottom of the list always results in the content pointer going back to the top of the list. The expectation is scrolling down the list will lock the view to where the scroll action ended. I also tried using TableLayout but the results are the same. Any ideas? the mainform below also has the setScrollableY() set.
int rows = 30;
Form hi = new Form("Test",new BoxLayout(BoxLayout.Y_AXIS));
hi.setScrollableY(true);
Container contents = new Container(new BoxLayout(BoxLayout.Y_AXIS));
contents.setScrollableY(true);
hi.add(contents);
for (int i = 0 ; i < rows;i++)
{
Label type = new Label("ROW+"+i);
type.setName(i+"");
type.setTextPosition(Component.TOP);
contents.addComponent(type);
}
mainform.addComponent(hi);
Remove this line:
contents.setScrollableY(true);
You can only have one scrollable container in a hierarchy and you chose the Form. When you nest scrollables the gesture gets picked by one of them and it becomes an issue. Unlike the desktop where you can click on a specific scrollbar in a refined way, in touch devices you can't pick a specific container to scroll.
I have a written a custom toolbar. And I am having tough time to make it work (design wise). I have a couple of questions regarding it.
1)The main issue I am facing is to place the menu icons in their exact positions. When I tested it in different devices the gaps betn them is different.I have used table layout and grid layout for the menu icons as well & the logo in layered layout but the result is not good.
Code:
void addTitle(Form form, Resources theme) {
Toolbar toolbar = new Toolbar();
form.setToolbar(toolbar);
Container containerTitle = new Container(new BorderLayout());
Image titleImage = theme.getImage("toolbar_bg.jpg");
containerTitle.getAllStyles().setBgImage(titleImage);
containerTitle.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_HORIZONTAL);
containerTitle.setPreferredH(titleImage.getHeight());
ScaleImageButton ruslanLogo = new ScaleImageButton();
toolbar.setTitleComponent(LayeredLayout.encloseIn(containerTitle,
FlowLayout.encloseCenter(ruslanLogo)));
Image ruslanLogoImage = theme.getImage("ruslanLogo.png").scaledWidth(toolbar.getPreferredH() - 180);
ruslanLogo.setIcon(ruslanLogoImage);
Image emergencyImage = theme.getImage("emergency.png");
Image receipeImage = theme.getImage("receipe.png");
Image fmImage = theme.getImage("fm.png");
Image gameImage = theme.getImage("game.png");
TableLayout tableLayout = new TableLayout(1, 5);
//GridLayout gridLayout = new GridLayout(5);
Container tableContainer = new Container(tableLayout);
Button emergencyButton = getButton(emergencyImage);
emergencyButton.getAllStyles().setAlignment(Label.CENTER);
Button fmButton = getButton(fmImage);
fmButton.getAllStyles().setAlignment(Label.CENTER);
Button gameButton = getButton(gameImage);
gameButton.getAllStyles().setAlignment(Label.CENTER);
Button receipeButton = getButton(receipeImage);
receipeButton.getAllStyles().setAlignment(Label.CENTER);
Button transparentButton = getButton(receipeImage);
transparentButton.getAllStyles().setAlignment(Label.CENTER);
transparentButton.setVisible(false);
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(emergencyButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(fmButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(transparentButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(gameButton));
tableContainer.addComponent(tableLayout.createConstraint().widthPercentage(20), BoxLayout.encloseY(receipeButton));
containerTitle.addComponent(BorderLayout.SOUTH, tableContainer);
toolbar.revalidate();
}
2)I have checked the width and preferred width, they differs. Does it affects the design?
int width = emergencyButton.getWidth(); //60
int preferredwidth = emergencyButton.getPreferredW(); //74
3)In above code, I used the bg image height to set the height of the toolbar. "containerTitle.setPreferredH(titleImage.getHeight());" Is it the good way to set height? Because the height changes slightly in android mobiles I have tested, however it looks horribly big in tabs, and I tested it in different simulator, the height differs greatly. How have you set the toolbar height in normal toolbar?
Image titleImage = theme.getImage("toolbar_bg.jpg");
containerTitle.getAllStyles().setBgImage(titleImage);
containerTitle.getAllStyles().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_HORIZONTAL);
containerTitle.setPreferredH(titleImage.getHeight());
ScaleImageButton ruslanLogo = new ScaleImageButton();
toolbar.setTitleComponent(LayeredLayout.encloseIn(containerTitle,
FlowLayout.encloseCenter(ruslanLogo)));
4)How can I set the width of icon?
Image emergencyImage = theme.getImage("emergency.png");
Button emergencyButton = getButton(emergencyImage);
if I just do this, some devices the icon is too big.If I scale it eg: emergencyImage.scaledWidth(screenwidth/8) , the image quality is bad.If I set preferredW like emergencyButton.setPreferredW(100), the img width varies vastly in different devices. PS the images in the theme are saved as multiImage
Setting the preferred width/height is problematic as it implies the inverse dimension and might have quite a few implications. I noticed you used:
Image ruslanLogoImage = theme.getImage("ruslanLogo.png").scaledWidth(toolbar.getPreferredH() - 180);
Which sets the width based on the preferred height instead of the width/5 or something like that. It also sets the value based on preferred height before the toolbar construction is done so things will behave differently.
Preferred width includes padding which might affect your design. I would suggest creating a center aligned 0 padding/margin UIID in the designer and setting it to all of your components to eliminate padding/margin differences and shorten your code.
I want to append a child control (button) programmatically inside a border left corner at run time based on event of a check box. my code on check box true value:
var btn = new System.Windows.Controls.Primitives.ToggleButton();
btn.Style = App.Current.Resources["ToggleButtonStyle"] as Style;
ctrlBorder.Child = btn;
ctrlBorder.Tag = btn;
Now the issue is if i am adding as child, all other controls inside the control as invisible and only btn is displayed. How can I append a btn inside a border control.
Also, on unchecking the checkbox the btn should disappear.
Any help is greatly appreciated!
By assigning ctrlBorder.Child you overwrite its only child (one allowed for border control). Try to append your control to the actual child of the border (Grid? StackPanel?)
see https://stackoverflow.com/a/1871229/1346098 :
Grid tmpGrid = ctrlBorder.Child as Grid;
tmpGrid.SetRow(btn, 3);
tmpGrid.SetColumn(btn, 4);
tmpGrid.Children.Add(btn);
I have to increase height of windows form after I clicked one button.
I need to do this programmatically cause I try to do this with xml code and did it well ,but it work every time I click button, I need to animate just once with clicking just one button
you can use double animation to change the height property.In your button_click event write the code for double animation.
DoubleAnimation dblanim = new DoubleAnimation();
dblanim.To =200;
dblanim.Duration = TimeSpan.FromSeconds(3);
this.BeginAnimation(HeightProperty, dblanim);
use dblanim.To property to set the height of your window.
I use this code to produce a print-preview window.
using (XpsDocument doc = new XpsDocument(fileName, FileAccess.Read))
{
FixedDocumentSequence fds = doc.GetFixedDocumentSequence();
using (var reader = new System.Xml.XmlTextReader(new StringReader(xaml)))
{
Window preview = System.Windows.Markup.XamlReader.Load(reader) as Window;
DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(preview, "dv1") as DocumentViewer;
dv1.Document = fds as IDocumentPaginatorSource;
dv1.FitToMaxPagesAcross(1);
// show the dialog
preview.ShowDialog();
}
}
But the preview window typically shows beneath the main Window. How can I get the preview to remain on top?
This code dynamically generates a Window from a simple XAML template at runtime, but that particular aspect of the code shouldn't be relevant to the problem I'm having.
Duplicate:
How do I focus a modal WPF Window when the main application window is clicked?
Set the Owner property of the preview window to the current window before showing the dialog.
preview.Owner = // the current window
preview.ShowDialog();