This question already has answers here:
Xamarin Forms - how to add background image to a content page
(2 answers)
Closed 5 years ago.
Guys Im having a little trouble trying to make an image the background for a certain page. Im trying to do it via the embedded method mentioned here:https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Embedded_Images
.For some reason when I run the app, it crashes. I think something went wrong at 'BackgroundImage =' line cause I kinda guessed when I did that. When I comment out that line, the app loads fine, just without the background image. I used build action = content and copy to output directory as settings...
public class LoginPage : ContentPage
{
Entry emailBox = new Entry();
Entry passwordBox = new Entry();
Button createAccount = new Button();
Button forgotPassword = new Button();
StackLayout layout = new StackLayout();
Image embeddedImage = new Image { Source = ImageSource.FromResource("Charity.Properties.hands-426x640.jpg") };
public LoginPage()
{
Title = "Login";
BackgroundColor = Color.LightPink;
BackgroundImage = "Charity.Properties.hands-426x640.jpg";
emailBox.Placeholder = "email";
emailBox.BackgroundColor = Color.LightPink;
emailBox.PlaceholderColor = Color.HotPink;
passwordBox.Placeholder = "password";
passwordBox.BackgroundColor = Color.LightPink;
passwordBox.PlaceholderColor = Color.HotPink;
passwordBox.IsPassword = true;
createAccount.Text = "create an account";
createAccount.TextColor = Color.HotPink;
createAccount.Font = Font.SystemFontOfSize(NamedSize.Medium);
createAccount.BorderWidth = 0;
createAccount.HorizontalOptions = LayoutOptions.Center;
createAccount.VerticalOptions = LayoutOptions.CenterAndExpand;
forgotPassword.Text = "recover password";
forgotPassword.TextColor = Color.HotPink;
forgotPassword.Font = Font.SystemFontOfSize(NamedSize.Medium);
forgotPassword.BorderWidth = 0;
forgotPassword.HorizontalOptions = LayoutOptions.Center;
forgotPassword.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.VerticalOptions = LayoutOptions.End;
layout.BackgroundColor = Color.LightPink;
layout.Children.Add(emailBox);
layout.Children.Add(passwordBox);
layout.Children.Add(createAccount);
layout.Children.Add(forgotPassword);
Content = layout;
}
}
This works, after much trial and error I only needed to add the image to both .Droid(drawable) and .iOS(resources) folders. I had not added it to the iOS folder previously, hence it kept crashing when I ran on an iOS simulator.
Image image = new Image();
public LoginPage()
{
Title = "Login";
BackgroundImage = "hands426x640.jpg";}
Related
I am trying to make a TextBox locked by using OpenXML SDK. I've tried this method but the TextBox NoTextEdit is not working.
public DocumentFormat.OpenXml.Presentation.Shape GenerateShape(string StrText)
{
DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape();
DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "ID",Hidden=true ,Description="Do not Remove" ,MCAttributes=null };
DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
Drawing.ShapeLocks shapeLocks1 = new Drawing.ShapeLocks() { NoTextEdit = true, NoGrouping = true,NoMove=true,NoSelection=true,NoEditPoints=true ,NoAdjustHandles=true ,NoRotation=true,NoChangeArrowheads=true,NoChangeAspect=true,NoChangeShapeType=true,NoResize=true};
nonVisualShapeDrawingProperties1.Append(shapeLocks1);
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.SubTitle, Index = (UInt32Value)1U };
applicationNonVisualDrawingProperties1.Append(placeholderShape1);
nonVisualShapeProperties1.Append(nonVisualDrawingProperties1);
nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1);
nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1);
DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody();
Drawing.BodyProperties bodyProperties1 = new Drawing.BodyProperties();
Drawing.ListStyle listStyle1 = new Drawing.ListStyle();
Drawing.TextShape shp = new Drawing.TextShape();
Drawing.Paragraph paragraph1 = new Drawing.Paragraph();
Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new Drawing.EndParagraphRunProperties() { Language = "en-US" ,Dirty=false };
paragraph1.Append(GenerateRun(StrText));
paragraph1.Append(endParagraphRunProperties1);
textBody1.Append(bodyProperties1);
textBody1.Append(listStyle1);
textBody1.Append(paragraph1);
shape1.Append(nonVisualShapeProperties1);
shape1.Append(shapeProperties1);
shape1.Append(textBody1);
return shape1;
}
public Drawing.Run GenerateRun(string StrText)
{
Drawing.Run run1 = new Drawing.Run();
Drawing.RunProperties runProperties1 = new Drawing.RunProperties() { Language = "en-US", Dirty = false };
runProperties1.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
Drawing.Text text1 = new Drawing.Text();
text1.Text = StrText;
Drawing.SolidFill solidFill2 = new Drawing.SolidFill();
Drawing.SchemeColor schemeColor = new Drawing.SchemeColor();
string y = System.Drawing.Color.Transparent.ToArgb().ToString("X");
Drawing.RgbColorModelHex rgbColorModelHex2 = new Drawing.RgbColorModelHex() { Val = "FFFFFF" };//Set Font-Color to Blue (Hex "0070C0").
solidFill2.Append(rgbColorModelHex2);
runProperties1.Append(solidFill2);
Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
run1.Append(runProperties1);
run1.Append(text1);
return run1;
}
Everything works fine except editing. Still the user can edit the TextBox values by double clicking it. How can I avoid this ?
Is there any permanent solution to prevent editing ? Please help me to find a better solution.
Thanks in advance
By researching and communications with the MVP team I've pointed out that there is no way to Protect the TextBox from editing.
As Cindy Meister mentioned in the comments,
Are you able to do it in the PowerPoint application user interface? If not, then Open XML cannot do it... If yes, you can.
If you do not want to text to be changed , Just change it as image then lock that by using NoSelection=true/1 and NoMove=true/1 properties. If you enable these properties the user can't either delete nor change it's position.
For your ref: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_windows8-mso_2016/shape-lock-is-not-working/c1705b55-d2aa-4adb-b538-574ed2fc8eca?tm=1579265435636&page=1&rtAction=1579495439869
In FormField "HH" i am trying to make text as link, but it is readed only as string text, it is not clickable.
I use Aspose.Pdf v.11.6.0.
var doc = new Aspose.Pdf.Document(pdfFileStream);
var pdfForm = new Aspose.Pdf.Facades.Form(doc);
pdfForm.FillField("Name", model.Name.ToUpper());
pdfForm.FillField("ISOS", model.NumberISOS.ToUpper());
pdfForm.FillField("Info", dateInfo);
pdfForm.FillField("HH", "http://www.somewebsite.com");
I use this code:
Page page = (Page)doc.Pages[1];
var text = new TextFragment("index");
text.Position = new Position(200, 300);
Aspose.Pdf.WebHyperlink link = new
WebHyperlink("www.google.com");
text.Hyperlink = link;
page.Paragraphs.Add(text);
but new Position(200, 300); values not responding.
Here is my solution, because position does not work, i move the link with margins. This worked for me.
Page page = (Page)doc.Pages[1];
var text = new TextFragment("LINK");
text.Position = new Position(300, 300);
Aspose.Pdf.WebHyperlink link = new WebHyperlink("www.google.com");
text.Hyperlink = link;
text.Margin.Left = -48;
text.Margin.Top = 687;
text.Margin.Bottom = -150;
text.TextState.Underline = true;
text.TextState.FontSize = 11;
text.TextState.ForegroundColor = Aspose.Pdf.Color.DeepSkyBlue;
text.TextState.BackgroundColor = Aspose.Pdf.Color.White;
page.Paragraphs.Add(text);
This question already has answers here:
WPF Image Command Binding
(5 answers)
Closed 4 years ago.
I am new to C# and WPF, and I want to make something like Movie Library with MySQL as a database to show the image and the title using Stackpanel.
I don't know how to add click event on an image programmatically Because I'm not using the image in Xaml.
Also, can Stackpanel have 3x3 or 4x4 grid instead only have 1 column?
Screenshot of my program:
Here is My Code
public void FillData()
{
int id = 1;
for (int i = id; i < 100; i++)
{
MySqlCommand cmd;
cmd = koneksi.CreateCommand();
cmd.CommandText = "select * from movie_list where id_movie = '" + i + "'";
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
if (ds.Tables[0].Rows.Count == 1)
{
string cover = (String)(ds.Tables[0].Rows[0]["cover"]);
string titles = (String)(ds.Tables[0].Rows[0]["title"]);
StackPanel Sp = sp;
StackPanel Sp2 = sp2;
Sp.Orientation = Orientation.Horizontal;
Sp2.Orientation = Orientation.Horizontal;
var picture = new Image
{
Name = "pb" + i,
Source = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + cover, UriKind.Absolute)),
RenderSize = new Size(100,150),
Margin = new Thickness(20,0,20,0),
};
var title = new Label
{
Name = "sp" +i,
Content = titles,
Width = 120,
Margin = new Thickness(10, 0, 20, 0),
HorizontalContentAlignment = HorizontalAlignment.Center,
};
Sp.Children.Add(picture);
Sp2.Children.Add(title);
}
}
}
You really should separate the data access code from your UI code.
In the UI, use an ItemsControl with the ItemsSource set to your DataSet. Set the ItemsTemplate to a DateTemplate with the controls you require for each item.
Using a ListBox will handle the item selection rather than worrying about click events for the Image and other controls.
If you want a grid layout rather than a straight linear list, you can use a UniformGrid as the ItemsPanelTemplate.
You can add an event handler to the picture object you're creating:
picture.MouseUp += (s, e) => {
// Do something funny.
};
var picture = new Image();
picture.MouseLeftButtonUp += (s, e) =>
{
//[your code goes here]
};
Besides that you absolutely shouldn't mix your database code with your UI code, you can just subscribe to the MouseDown (or MouseUp, if it should be like a click) event on your Image and execute whatever you want:
picture.MouseDown += (sender, args) =>
{
Foo();
};
Im having some problems with the Children.Add() function of a Stack Layout. There is an error in the code below which says " There is no argument that corresponds to the required formal parameter 'value' of 'SettersExtentions.Add(IList, Bindable Property, object)' ". The error is a curly red underline under all the .Add words.
public class LoginPage : ContentPage
{
public string email { get; set; }
public string password { get; set; }
Entry emailBox = new Entry();
Entry passwordBox = new Entry();
Button createAccount = new Button();
Button forgotPassword = new Button();
Layout layout = new StackLayout();
public LoginPage()
{
Title = "Login";
emailBox.Placeholder = "email";
passwordBox.Placeholder = "password";
passwordBox.IsPassword = true;
createAccount.Text = "Create Account";
createAccount.Font = Font.SystemFontOfSize(NamedSize.Large);
createAccount.BorderWidth = 1;
createAccount.HorizontalOptions = LayoutOptions.Center;
createAccount.VerticalOptions = LayoutOptions.CenterAndExpand;
forgotPassword.Text = "Forgot Password";
forgotPassword.Font = Font.SystemFontOfSize(NamedSize.Large);
forgotPassword.BorderWidth = 1;
forgotPassword.HorizontalOptions = LayoutOptions.Center;
forgotPassword.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.Children.Add(emailBox);
layout.Children.Add(passwordBox);
layout.Children.Add(createAccount);
layout.Children.Add(forgotPassword);
Content = layout;
}
public void Check(string email, string password, string cpassword)
{
}
}
Layout.Children is a readonly IReadOnlyList<Element> so you wont be able to add to it.
However StackLayout.Children is IList<T> which will allow you to add children
change
Layout layout = new StackLayout();
to
StackLayout layout = new StackLayout();
This will allow you to be able to add the child elements to the layout.
im really new to c# and Xamarin Forms but can someone please explain to me why I'm getting an error in the last line of code below ?
Visual Studio is indicating a curly red underline on the word Children on the last line of this code indicating that there is some syntax error but I don't see why that is an error since I'm just accessing a member of the class ....
var content = new ContentPage();
content.Title = "Appuler";
Label CompanyName = new Label();
CompanyName.HorizontalTextAlignment = TextAlignment.Center;
CompanyName.Text = "Test";
Button NextPage = new Button();
NextPage.Text = "Next Page";
NextPage.Font = Font.SystemFontOfSize(NamedSize.Large);
NextPage.BorderWidth = 1;
NextPage.HorizontalOptions = LayoutOptions.Center;
NextPage.VerticalOptions = LayoutOptions.CenterAndExpand;
content.Content = new StackLayout();
content.Content.VerticalOptions = LayoutOptions.CenterAndExpand;
content.Content.Children.Add(CompanyName);
Refactor the last few lines to the following
var layout = new StackLayout();
layout.VerticalOptions = LayoutOptions.CenterAndExpand;
layout.Children.Add(CompanyName);
content.Content = layout;
ContentPage.Content does not have that Children property as it is a View. StackLayout, however does have a Children property that can be accessed.
populate the layout control's accessible properties and then assign it to the Content property of the ContentPage.