I want to fetch a set of images from the database and display them in the application. The number of images varies according to each user of the application. The user is the one who adds the images to the database and they are displayed to him in the form (Horizontal layout)
in c# windows app i can use this code to create picture box then add it to flowLayoutPanel
and when click on image, do something
var pic = new PictureBox
{
Name = "Pic" + txt.id.ToString(),
Size = new Size(118, 114),
Image = Image.FromStream(byteStream),
SizeMode = PictureBoxSizeMode.Zoom,
BorderStyle = BorderStyle.FixedSingle,
Cursor = Cursors.Hand,
};
pic.Click += Pic_Click;
flowLayoutPanel.Controls.Add(pic);
how can i do the same in xamarin
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’m trying to display contents. Contents can be a combination of image, video & text. Each one of them has a start date time & end date time.
I could display one image using tag but I couldn’t display series of images in a loop. Its displaying only last image or video. Immediate help appreciated.
Code snippet as follows -
// Check if Content if its an Image
if (dataTable.Rows[nCnt][1].Equals("I"))
{
imageSource = new BitmapImage(new Uri(strContent));
Image1.Visibility = Visibility.Visible;
Image1.Source = imageSource;
}
else
// Check if Content if its an Video
if (dataTable.Rows[nCnt][1].Equals("V"))
{
MyVideo1.Source = new Uri(strContent);
MyVideo1.Visibility = Visibility.Visible;
MyVideo1.Play();
}
You are filling the same image and video container(Image1, MyVideo1), with diferent images and videos. So the last one is the only one displayed. You should create a collection of images and videos. List<YourMediaType> or ObservableCollection<YourMediaType> if you are using MVVM.
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.
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();