Reputation: 254
I have a sub project wich is a class and contains DataLib.cs and an user controll MediumTile.xaml. This user control will be the generated to an image to use it as tile background. But before I have to change a few thing dynamicly. So how can I get controll above the LayoutRoot inside MediumTile.xaml for example to set the background color?
Something like this:
MediumTile.LayoutRoot.Background = new SolidColorBrush(Color.FromArgb(255, 206, 23, 23);
Upvotes: 0
Views: 1006
Reputation: 811
MediumTile.xaml
probably exists in some kind of namespace.
You can find the namespace of the UserControl in the top of the file beside the x:Class declaration.
Typically it'll look something like
x:Class="MyProject.UserControls.MediumTile"
if your project is set up normally.
If you look at the MediumTile.xaml.cs
, you should see a namespace like so
namespace MyProject.UserControls
{
public partial class MediumTile : UserControl
...
First off, you will need to reference your subproject.
Assuming you have a project structure like so...
CurrentProject/
-MyPage.xaml
SubProject/
-MediumTile.xaml
Right-click your Solution in Visual Studio and click Properties
.
Under Properties select Project Dependencies
.
Choose the CurrentProject in the dropdown.
In the Depends On
checkbox field, choose the SubProject.
Click on StartUp Project
in the side bar.
Make sure Single StartUp Project
points to CurrentProject. If not, set it.
Now you're done setting up, you'll need to actually use MediumTile.xaml
now.
To use the MediumTile UserControl in another XAML file, you will need to declare
xmlns:customControls="clr-namespace:MyProject.UserControls"
inside the page header, and call
<ListBox.ItemTemplate>
<DataTemplate>
<customControls:MediumTile/>
...
To use this UserControl in another CS file, you will need to import the namespace
using MyProject.UserControls;
at the top of the page, and reference your control like so (depending on your usercontrol's constructor),
MediumTile mediumTile = new MediumTile()
About your LayoutRoot
problem, you can simply set the Background color directly on the UserControl. UserControl inherits from Control, which has the Background property already.
Upvotes: 1
Reputation: 10507
I've never done it for windows phone 8
, but for normal desktop applications, you can do it by adding the following references:
Then you can create and access a Control
in a normal way.
Upvotes: 0