Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting an element contained in another control
Message
De
09/03/2008 12:01:57
 
 
À
08/03/2008 16:50:25
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01300068
Message ID:
01300184
Vues:
9
This message has been marked as the solution to the initial question of the thread.
>Still feeling brain dead on XAML :(
>
>Simple control:
>
>
><UserControl x:Class="cdsThemes.TestControl2"
>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>    Height="300" Width="300">
>    <Grid Background="BlanchedAlmond">
>  <TextBox Height="23"
>             Margin="25,103,0,0"
>             Name="textBox1"
>             VerticalAlignment="Top"
>             HorizontalAlignment="Left"
>             Width="120">Blah Blah Blah</TextBox>
>  </Grid>
></UserControl>
>
>And I use it in another simple control:
>
>
><UserControl x:Class="cdsThemes.TestControl1"
>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>    xmlns:local="clr-namespace:cdsThemes"
>    Height="300" Width="300">
>    <Grid>
>    <local:TestControl2 x:Name="testControl2"></local:TestControl2>
>  </Grid>
></UserControl>
>
>
>Lets say I want to change the margin on textBox1 inside of TestControl2 from the XAML in TestControl1. How do I do that?
>
>My actual situation may be harder because textBox1 in that case is a custom control based on a TextBox defined in another assembly. But I can't even get this one to work, so I figured I'd start with the simpler problem.
>
>I can do it easy in C#
>
>
>testControl2.textBox1.Margin = new Thickness(1, 1, 1, 1);
>
>
>just can't seem to work out the XAML.

For a rough and ready solution you can create a public property on the contained control. e.g:
public Thickness TextBoxMargin
        {
            get { return textBox1.Margin; }
            set { textBox1.Margin = value; }
        }
Then, in containing controls XAML you can use:
<local:TestControl2 x:Name="testControl2" TextBoxMargin="1,1,1,1"></local:TestControl2>
But I think creating a DependencyProperty is the 'correct' answer.
HTH,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform