Coding4Fun InputPrompt style text box - c#

I'm trying to style the Coding4Fun InputPrompt control to set a border on the textbox element and change the unselected colour in code.
I've not been able to find any examples, and visual studio doesn't recognise the control properly (InputPrompt is displayed in red with no intellisense, but the project runs fine).
I've managed to set some colours and update the buttons, but no success on the textbox.
Can anyone point me in the right direction please?
Here is what I have so far:
var input = new InputPrompt
{
Title = "Title",
Message = "My Message",
IsCancelVisible = true,
Background = new SolidColorBrush(Color.FromArgb(0xCC, 0x00, 0x00, 0x00)),
Foreground = new SolidColorBrush(Colors.White)
};
input.Completed += input_Completed;
input.InputScope = new InputScope
{
Names = {new InputScopeName() {NameValue = InputScopeNameValue.TelephoneNumber}}
};
foreach (var button in input.ActionPopUpButtons)
{
button.Foreground = new SolidColorBrush(Colors.White);
button.BorderBrush = new SolidColorBrush(Colors.White);
button.Margin = new Thickness(0,5,0,0);
}
input.BorderThickness = new Thickness(5.0);
input.Show();

Related

NoTextEdit ShapeLock is not working - OpenXML SDK

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

WPF TabItem Style screws up the control positions

I created a new TabItem Style which looks the way I wanted. But now it screws up the positions of all the controls which are placed on the TabItem. It moves them from the top left area to the right bottom area of the TabItem. Any help would be highly appreciated. (Yes, I am sure I need the style in C# NOT in XAML)
var functionReturnValue = new Style();
ControlTemplate L_NewControlTemplate = new ControlTemplate(typeof(TabItem));
FrameworkElementFactory L_ElemFactory = new FrameworkElementFactory(typeof(Border));
L_ElemFactory.SetBinding(Border.FocusVisualStyleProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("FocusVisualStyle") });
L_ElemFactory.SetBinding(Border.BackgroundProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("Background") });
L_ElemFactory.SetBinding(Border.BorderBrushProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("BorderBrush") });
L_ElemFactory.SetBinding(Border.BorderThicknessProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("BorderThickness") });
//L_ElemFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(0,12,0,0));
L_ElemFactory.SetValue(Border.SnapsToDevicePixelsProperty, true);
FrameworkElementFactory L_ContentPresenter = new FrameworkElementFactory(typeof(ContentPresenter));
L_ContentPresenter.SetValue(ContentPresenter.ContentSourceProperty, "Header");
L_ContentPresenter.SetBinding(ContentPresenter.HorizontalAlignmentProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("HorizontalContentAlignment") });
L_ContentPresenter.SetBinding(ContentPresenter.VerticalAlignmentProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("VerticalContentAlignment") });
L_ContentPresenter.SetBinding(ContentPresenter.SnapsToDevicePixelsProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("SnapsToDevicePixels") });
L_ElemFactory.AppendChild(L_ContentPresenter);
L_NewControlTemplate.VisualTree = L_ElemFactory;
Trigger NewTrigger;
//Trigger IsEnabled = true
NewTrigger = new Trigger { Property = TabItem.IsEnabledProperty, Value = true };
NewTrigger.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, F_Background));
L_NewControlTemplate.Triggers.Add(NewTrigger);
//Trigger MouseOver
NewTrigger = new Trigger { Property = TabItem.IsMouseOverProperty, Value = true };
NewTrigger.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, F_MouseOver));
L_NewControlTemplate.Triggers.Add(NewTrigger);
//Trigger Selected
NewTrigger = new Trigger { Property = TabItem.IsSelectedProperty, Value = true };
NewTrigger.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, F_Background));
L_NewControlTemplate.Triggers.Add(NewTrigger);
//Trigger Selected
NewTrigger = new Trigger { Property = TabItem.IsSelectedProperty, Value = false };
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, L_IsDeActive));
L_NewControlTemplate.Triggers.Add(NewTrigger);
functionReturnValue.Setters.Add(new Setter(TabItem.FocusVisualStyleProperty, null));
functionReturnValue.Setters.Add(new Setter(TabItem.BackgroundProperty, F_Background));
functionReturnValue.Setters.Add(new Setter(TabItem.BorderBrushProperty, Brushes.Green));
functionReturnValue.Setters.Add(new Setter(TabItem.BorderThicknessProperty, new Thickness(0)));
functionReturnValue.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
functionReturnValue.Setters.Add(new Setter(TabItem.HorizontalContentAlignmentProperty, System.Windows.HorizontalAlignment.Center));
functionReturnValue.Setters.Add(new Setter(TabItem.VerticalContentAlignmentProperty, System.Windows.VerticalAlignment.Center));
functionReturnValue.Setters.Add(new Setter(TabItem.PaddingProperty, new Thickness(0)));
functionReturnValue.Setters.Add(new Setter(TabItem.MarginProperty, new Thickness(-4, -4, 0, 0)));
functionReturnValue.Setters.Add(new Setter(TabItem.TemplateProperty, L_NewControlTemplate));
return functionReturnValue;
So it turns out your first problem is these two lines:
functionReturnValue.Setters.Add(new Setter(TabItem.HorizontalContentAlignmentProperty, System.Windows.HorizontalAlignment.Center));
functionReturnValue.Setters.Add(new Setter(TabItem.VerticalContentAlignmentProperty, System.Windows.VerticalAlignment.Center));
Just omit those; they're acting on the tab item content, not on the header.
To restyle the header, you have a lot of options.
This will put a 20 unit margin around your content presenter:
L_ContentPresenter.SetValue(ContentPresenter.MarginProperty, new Thickness(20));
20's pretty arbitrary; of course you can use your own values. This will give it 20 unit side margins and 10 unit top/bottom margins:
L_ContentPresenter.SetValue(ContentPresenter.MarginProperty, new Thickness(20, 10, 20, 10));
You could also put a Border or something inside the header control template, surrounding the ContentPresenter, and do something with the padding or margins of that containing control. This kind of thing is infinitely easier to work with in XAML, so I'm not going to the trouble of doing that in C#.
You could have the TabItem style set HeaderTemplate, which is a DataTemplate:
var headerTemplate = new DataTemplate();
var label = new FrameworkElementFactory(typeof(Label));
label.SetBinding(Label.ContentProperty, new Binding());
label.SetValue(Label.MarginProperty, new Thickness(16, 12, 16, 12));
headerTemplate.VisualTree = label;
functionReturnValue.Setters.Add(new Setter(TabItem.HeaderTemplateProperty, headerTemplate));
In closing, I'd like to reiterate that whatever you need to do at runtime to Styles, you can do more easily and far more maintainably in XAML than in C#.

Controls created on one thread cannot be parented to a control on a different thread - Adding DataGridView to TabPage to TabControl

I am pragmatically creating TabPage with DataGridView. The TabPage's are appearing correctly, but they are missing the DataGridView. Anyone able to discern why they DGV's are not appearing with the tabs? The LoadDataGridToTab is in the correct form. It is being called from another Form though. Should?
public void LoadDataGridToTab(Main main, string category)
{
try
{
//Set Cell Style
var dataGridViewCellStyle = new DataGridViewCellStyle
{
Alignment = DataGridViewContentAlignment.MiddleLeft,
BackColor = SystemColors.Control,
Font = new Font("Microsoft Sans Serif", 8.25F,
FontStyle.Regular, GraphicsUnit.Point, 0),
ForeColor = SystemColors.WindowText,
SelectionBackColor = SystemColors.Highlight,
SelectionForeColor = SystemColors.HighlightText,
WrapMode = DataGridViewTriState.True
};
//Make the Grid
var grid = new DataGridView
{
Name = "dgv_" + category,
Text = category,
Visible = true,
Dock = DockStyle.Fill,
AllowUserToAddRows = false,
AllowUserToDeleteRows = false,
AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize,
ColumnHeadersDefaultCellStyle = dataGridViewCellStyle,
DataSource = Auction.CacheAuctionsDataSet.Tables[category]
};
//Binding
//var source = new BindingSource();
//source.DataSource = CacheAuctionsDataSet.Tables[category];
//Made the Tab
var tmpTabPage = new TabPage(category)
{
Name = "tabctrl_" + category,
Text = category,
Visible = true
};
//Add the Grid to the Tab
tmpTabPage.Controls.Add(grid);
tmpTabPage.Refresh();
//Add the Tab to the Control
tabctrl_Auctions.Controls.Add(tmpTabPage);
tabctrl_Auctions.Refresh();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
You need to use the Invoke method.
An example is found here https://stackoverflow.com/a/253150/2633161

How to use MonoTouch.Dialog's ActivityElement?

I might be missing something here, but this code:
this.oSectionDRs = new Section()
{
new ActivityElement()
{
Caption = Locale.GetLocale("Settings_Loading"),
Animating = true
}
};
// To begin with just show a loading indicator.
this.Root = new RootElement (Locale.GetLocale("Settings_Select"))
{
this.oSectionDRs
};
Does not show any animated thingy. It is showing the label only. How can I get the animated star?
Using this code:
var root = new RootElement("foo");
root.Add (new Section("foo", "bar") {
new ActivityElement()
{
Caption = "foo",
Animating = true
}
});
var dvc = new DialogViewController(root, false);
window.RootViewController = dvc;
I get both the caption and the activity scroller thing. Not sure it helps you tho! I was just using the built in MT.D.

WP7 - Fade user control via code, not XAML

I'm trying to popup a user control and then fade it out over 3 seconds. I'm trying to use the following code but I keep getting incorrect parameter value on the assignment of Popup.LoadedEvent as well as Splash.LoadedEvent. What am I doing wrong?
Splash s = new Splash();
DoubleAnimation fade = new DoubleAnimation()
{
Duration = new Duration(TimeSpan.FromMilliseconds(3000)),
From = 1.0,
To = 0.0,
RepeatBehavior = new RepeatBehavior(1)
};
fade.Completed += new EventHandler(fade_Completed);
this.popup = new Popup();
this.popup.Child = s;
EventTrigger et = new EventTrigger();
et.RoutedEvent = Popup.LoadedEvent;
Storyboard sb = new Storyboard();
sb.Children.Add(fade);
BeginStoryboard bs = new BeginStoryboard() { Storyboard = sb };
et.Actions.Add(bs);
this.popup.Triggers.Add(et);
this.popup.IsOpen = true;
I also cant seem to figure out where/how to set the target property.
Edit: I was able to get the answer using the link #Titan2782 provided. I've posted it in an answer below.
check out http://www.windowsphonegeek.com/articles/wp7-transitions-in-depth--custom-transitions it has some code to work with storyboard and set the target properties.
You should look into the transitions stuff in the windows phone toolkit: http://blogs.msdn.com/b/wfaught/archive/2010/11/15/transitions.aspx
its only a couple lines to get those transitions in.
You might have some issues here because you're using a popup, and the popup doesn't exist in the visual tree?
I have an example with a button in vb, shouldn't be hard to translate into c#:
Dim Fade As New Animation.DoubleAnimation
Fade.From = 0.5
Fade.To = 1
Fade.Duration = TimeSpan.FromSeconds(3)
Animation.Storyboard.SetTarget(Fade, button)
Animation.Storyboard.SetTargetProperty(Fade, New PropertyPath(Button.OpacityProperty))
Dim sb As New Animation.Storyboard
sb.Children.Add(highlight)
sb.Begin()
I suppose this works also with the Popup.
Thanks to #Titan2782 answer I was able to figure it out
Splash s = new Splash();
DoubleAnimation fade = new DoubleAnimation()
{
Duration = new Duration(TimeSpan.FromMilliseconds(4000)),
From = 1.0,
To = 0.0,
RepeatBehavior = new RepeatBehavior(1)
};
fade.Completed += new EventHandler(fade_Completed);
this.popup = new Popup();
this.popup.Child = s;
Storyboard.SetTargetProperty(fade, new PropertyPath(UIElement.OpacityProperty));
sb.Children.Add(fade);
Storyboard.SetTarget(sb, s);
this.popup.IsOpen = true;
sb.Begin();

Categories