views:

31

answers:

1

I have a ChildWindow control which has several TextBoxes, and a Button in it,. When I click the Button, I want to change the "IsReadOnly" property of one of the TextBoxes. In my button click event handler, all of the TextBox objects are "null".

Can someone explain why this is, and how I can access them?

Thanks for any help.

Edit:

<localCW:cwBase x:Class="Administration.cwAdd"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
            xmlns:localCW="clr-namespace:Administration.ChildWindows"
            xmlns:localCtrl="clr-namespace:Administration.Controls"
            Width="480"
            Height="460"
            Title="Add"
            Header="Add New"
            OkButtonText="Save">

<Grid x:Name="LayoutRoot"
      Margin="2">
    <Grid.RowDefinitions>
        <RowDefinition Height="30" />
        <RowDefinition Height="80" />
        <RowDefinition Height="30" />
        <RowDefinition Height="30" />
....
....
<TextBlock Text="Relative Path:"
               Grid.Row="2"
               Grid.Column="0"
               Margin="0,0,0,5"
               HorizontalAlignment="Right" />
    <Grid Grid.Row="2"
          Grid.Column="1"
          Width="250"
          HorizontalAlignment="Left">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="30" />
        </Grid.ColumnDefinitions>

        <localCtrl:RelativeURLTextBox x:Name="tbxNewUrl"
                                      Grid.Column="0"
                                      Margin="5 0 0 5"
                                      Width="215"
                                      HorizontalAlignment="Left"
                                      Text="{Binding RelativeURL, Mode=TwoWay}" />
        <Button Grid.Column="1"
                Margin="3"
                Width="24"
                Height="24"
                Click="btnEditRelURL_Click">
            <Button.Content>
                <Image Source="../images/edit_16px.png"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center" />
            </Button.Content>
        </Button>
    </Grid>




private void btnEditRelURL_Click(object sender, RoutedEventArgs e)
    {
        // Neither of these worked vvv
        tbxNewUrl.SetReadOnly(false);
        //this.Dispatcher.BeginInvoke ( () => {tbxNewUrl.SetReadOnly(false);});
    }
A: 

It appears that the issue is because I was attempting to access a control that was defined in the base class, instead of my derived class. I added a method to the base class to return the element based on the name, and it worked. Thanks for the help.

Sako73