How to set a background color of a control in windows 8 store application - background

I am designing an application and had to instantiate controls via code. The problem is that I am unable to change the background color. I tried to look all over the internet, but no succes. I have contacted the Microsoft support service, but no succes either.
I read that you normally change a color by using System.Color or System.ColorHelper. Both are not accesible in the application.
So how to solve the following problem:
TextBox^ txtID = ref new TextBox();
txtID->Background = ?;

I have the solution, first make a brush object and set the color and assign that color to your controls background. I used the following:
SolidColorBrush^ myBrush = ref new SolidColorBrush(Windows::UI::Colors::Red);
TextBox^ txtID = ref new TextBox();
txtID->Background = myBrush;

Related

How to change the background color of a windows context menu using the winapi

I am currently trying to customize a context menu in Outlook. For the regulars I have had a series of issues which can be seen in this question and with this question.
I would like to adjust the background color a little.
Dim hBrush As IntPtr = NativeMethodsEX.CreateSolidBrush(ColorTranslator.ToWin32(System.Drawing.Color.Red))
Dim mi As New NativeMethodsEX.MenuInfo
With mi
.cbSize = Marshal.SizeOf(mi)
.fMask = NativeMethodsEX.MIM_STYLE Or NativeMethodsEX.MIM_BACKGROUND Or NativeMethodsEX.MIM_APPLYTOSUBMENUS
.dwStyle = NativeMethodsEX.MNS_NOCHECK
.hbrBack = hBrush
End With
NativeMethodsEX.SetMenuInfo(aHwnd, mi)
This code however produces this;.
How can I also change the background of the left hand side or what even is the class name of that part of the window. Also it has a border as well. What is its class name or how can I either remove it or change it?

Add Image to Custom Task Pane Title in Outlook - VB.Net

I have created a custom task pane in VB.Net for Outlook using the Code given below and I would like to add more content to the header (image and a button) of the User Control instead of just the title. Is there a way I can achieve this?
myUserControl1 = New OutlookTaskPane
myUserControl1.TabStop = True
Dim width As Integer = myUserControl1.Width
myCustomTaskPane = Me.CustomTaskPanes.Add(myUserControl1, "My Custom Task Pane")
myCustomTaskPane.Width = width
myCustomTaskPane.Visible = True
myCustomTaskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange
Let me know if there is any other way of achieving this please.
Thanks.
Unfortunately the TaskPane header is not customizable. Only Add-in Express supports similar customizations using their implementation of Advanced Form Regions (although only the header icon and header color can be changed and you can't add Windows Forms controls to it). Another option is to implement your own type of Task Pane so you have complete control over the UI; see https://code.msdn.microsoft.com/OlAdjacentWindows/.

Force UI redraw after loading new resource files

I have defined 2 themes (Resource files containing colours - .xaml), one in the resource dictionary on app load and one added on a button click by the following code:
Application.Current.Resources.MergedDictionaries.Clear()
Dim lightTheme As New ResourceDictionary()
Dim lightThemeUri As New Uri("/MyApp.UI;component/Assets/ColourResourcesLight.xaml", UriKind.Relative)
lightTheme.Source = lightThemeUri
Application.Current.Resources.MergedDictionaries.Add(lightTheme)
The colours in the new light theme are defined with the same key as the dark theme (loaded when app loads). My controls are then bound to this key with a staticResource.
After the new resource file loads i would like to somehow update / force a redraw of the whole UI to allow my new theme to display. This works on the controls contained in pages that i then navigate to, however it does not update my navigation bar (Main Page). Every other page is loaded into a container on the main page.
I would like the navigation bar to also update.
Was wondering what the best way to do this was, i have tried updating the bindings by using :
Public Shared Sub ForceControlRebind(cntrl As Control, depprop As DependencyProperty)
Try
Dim BindExp As BindingExpression = cntrl.GetBindingExpression(depprop)
Dim Bind As Binding = BindExp.ParentBinding
cntrl.SetBinding(depprop, Bind)
Catch generatedExceptionName As Exception
Throw
End Try
End Sub
However the BindExp always returns nothing.
I have also tried forcing a UI redraw by using:
mainpage.InvalidateMeasure()
mainpage.InvalidateArrange()
mainpage.UpdateLayout()
I know the resource file is properly loaded as the properties have updated when i step into the controls

Windows 8 App - Programmatically Added Path Disappears

Any help with this would be much appreciated.
I am trying to build an app in Windows 8 using xaml and vb.
To test the process of adding a path dynamically to the UI I have created a class that draws a circle using a path (code below). The code fires when a button is tapped/clicked.
The circle then appears briefly near the centre of the screen but then disappears.
If I then count the children on the grid, the circle is counted. Its just not visible.
I'd like to understand what is happening and stop the circle from disappearing.
Dim path As New Windows.UI.Xaml.Shapes.Path
Dim rectG As New EllipseGeometry
rectG.Center = New Point(500, 500)
rectG.RadiusX = 100
rectG.RadiusY = 100
path.Data = rectG
path.Stroke = New SolidColorBrush(Windows.UI.Colors.LightGreen)
path.StrokeThickness = 1
path.Fill = New SolidColorBrush(Windows.UI.Colors.LightGreen)
path.Name = "TestName"
_TargetGrid.Children.Add(path)
Finally figured it out. I needed to set the column and row span property.
On the test I did it using the code although in a proper app it would probably make sense to use some kind of predetermined styling.
However, here is the code I added:
path.SetValue(Grid.ColumnSpanProperty, 5)
path.SetValue(Grid.RowSpanProperty, 5)

creating table at runtime in vb.net, image control doesnt have imageurl proerty

i am creating a table in vb.net code (htmltable) with htmltablerows and htmltablecell. I gave on image control but thatr control cant have the .imageurl property, which i need cause i have a handler image.ashx which brings image from the database.
heres' the code -
TD = New HtmlTableCell
Dim img As New HtmlImage()
img.ID = "image_" & rd("ID")
img.Style.Add("width", "100px")
img.Style.Add("height", "100px")
img.ImageUrl = "Image.ashx?id=" & rd("ID")
on the last line, "img.ImageUrl" i get this error -
'ImageUrl' is not a member of 'System.Web.UI.HtmlControls.HtmlImage'
how do i fix this?
ImageUrl is a member of the System.UI.WebControls.Image control. By contrast, you are using the direct HtmlImage control which is rendered exactly as an img tag would be. You should use the Src property of the HtmlImage control instead.