This is a migrated thread and some comments may be shown as answers.

Chage Background ReadOnlyVisualElement DatePicker by Code Behind

2 Answers 70 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Abner
Top achievements
Rank 1
Abner asked on 28 Apr 2014, 08:40 AM
Hello Guys,

I have been trying to change the gray background <Border ReadOnlyVisualElement to white, but I would like to do by code behind,the problem is when I try to get the element <Border ReadOnlyVisualElement using Border border = this.txtDatePickerIdle.ParentOfType<Border>(); didn't work because get the parent above, I tried Child as well and didn't work, I tried to using Immediate Window and navegate in the control but when I try to find the border is always 'NULL'.

I am running the code in the LayoutUpdated event.

The xaml is below, and I attached a file with the print of structure:
<
RadWatermarkTextBox x:Name="txtDatePickerIdle" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" AllowDrop="True" Background="#00FFFFFF" BorderBrush="#00FFFFFF" BorderThickness="1, 1, 1, 1" Foreground="#FF000000" HorizontalContentAlignment="Left" HorizontalScrollBarVisibility="Hidden" IsHitTestVisible="False" IsReadOnly="True" IsTabStop="False" Margin="0, 0, 15, 0" MinHeight="15" SelectedText="" SelectionBackground="#FF444444" SelectionForeground="#FFFFFFFF" SelectionLength="0" SelectionStart="0" TabNavigation="Once" Text="dd/MM/yyyy" UseLayoutRounding="False" VerticalScrollBarVisibility="Hidden">
  <Grid x:Name="RootElement" AllowDrop="True" Cursor="IBeam" UseLayoutRounding="False">
    <Border x:Name="Border" AllowDrop="True" Background="#00FFFFFF" BorderBrush="#00FFFFFF" BorderThickness="1, 1, 1, 1" CornerRadius="1, 1, 1, 1" UseLayoutRounding="False" />
    <Border x:Name="ReadOnlyVisualElement" AllowDrop="True" Background="#5EC9C9C9" CornerRadius="1, 1, 1, 1" UseLayoutRounding="False" />
    <Border x:Name="MouseOverVisual" Grid.ColumnSpan="2" Grid.RowSpan="2" AllowDrop="True" BorderBrush="#FFFFC92B" BorderThickness="1, 1, 1, 1" CornerRadius="1, 1, 1, 1" IsHitTestVisible="False" Opacity="0" UseLayoutRounding="False" Visibility="Collapsed" />
    <Border x:Name="DisabledVisualElement" AllowDrop="True" Background="#FFE0E0E0" BorderBrush="#FF989898" BorderThickness="1, 1, 1, 1" CornerRadius="1, 1, 1, 1" IsHitTestVisible="False" Opacity="0" UseLayoutRounding="False" />
    <ScrollViewer x:Name="ContentElement" AllowDrop="True" Background="#00FFFFFF" BorderBrush="#FF848484" Cursor="Arrow" Foreground="#FF000000" HorizontalContentAlignment="Stretch" HorizontalScrollBarVisibility="Hidden" IsTabStop="False" Margin="1, 1, 1, 1" UseLayoutRounding="False" VerticalAlignment="Center" VerticalContentAlignment="Stretch" VerticalScrollBarVisibility="Hidden">
      <Border AllowDrop="True" Background="#00FFFFFF" BorderBrush="#FF848484" UseLayoutRounding="False">
        <Grid AllowDrop="True" Background="#00FFFFFF" UseLayoutRounding="False">
          <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="Auto" />
          </Grid.ColumnDefinitions>
          <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
          </Grid.RowDefinitions>
          <ScrollContentPresenter x:Name="ScrollContentPresenter" AllowDrop="True" CanHorizontallyScroll="True" CanVerticallyScroll="True" Cursor="Arrow" UseLayoutRounding="False">
            <ScrollContentPresenter.Clip>
              <RectangleGeometry Rect="-1, 0, 103, 16" />
            </ScrollContentPresenter.Clip>
            <TextBoxView />
          </ScrollContentPresenter>
          <Border Grid.Column="1" Grid.Row="1" AllowDrop="True" Margin="0, 0, -1, -1" UseLayoutRounding="False" Visibility="Collapsed">
            <Border AllowDrop="True" BorderBrush="#FF848484" BorderThickness="0, 0, 1, 1" UseLayoutRounding="False" Visibility="Collapsed">
              <Border.Background>
                <RadialGradientBrush Center="0, 0" GradientOrigin="0, 0" RadiusX="1" RadiusY="1">
                  <GradientStopCollection>
                    <GradientStop Offset="0.066">#FF848484</GradientStop>
                    <GradientStop Offset="0.066">#FFBFBFBF</GradientStop>
                    <GradientStop Offset="0.29">#FFF0F0F0</GradientStop>
                  </GradientStopCollection>
                </RadialGradientBrush>
              </Border.Background>
            </Border>
          </Border>
          <ScrollBar x:Name="VerticalScrollBar" Grid.Column="1" AllowDrop="True" BorderBrush="#FF848484" BorderThickness="1, 0, 1, 0" Foreground="#FF000000" IsTabStop="False" Margin="0, 0, -1, 0" Maximum="0" MinHeight="15" MinWidth="15" UseLayoutRounding="False" ViewportSize="16" Visibility="Collapsed">
            <ScrollBar.Background>
              <LinearGradientBrush EndPoint="1, 0.5" StartPoint="0, 0.5">
                <GradientStopCollection>
                  <GradientStop Offset="0.257">#FFF0F0F0</GradientStop>
                  <GradientStop>#FFBFBFBF</GradientStop>
                </GradientStopCollection>
              </LinearGradientBrush>
            </ScrollBar.Background>
          </ScrollBar>
          <ScrollBar x:Name="HorizontalScrollBar" Grid.Row="1" AllowDrop="True" BorderBrush="#FF848484" BorderThickness="0, 1, 0, 1" Foreground="#FF000000" IsTabStop="False" Margin="0, 0, 0, -1" Maximum="0" MinHeight="15" MinWidth="15" Orientation="Horizontal" UseLayoutRounding="False" ViewportSize="101" Visibility="Collapsed">
            <ScrollBar.Background>
              <LinearGradientBrush EndPoint="1, 0.5" StartPoint="0, 0.5">
                <GradientStopCollection>
                  <GradientStop Offset="0.257">#FFF0F0F0</GradientStop>
                  <GradientStop>#FFBFBFBF</GradientStop>
                </GradientStopCollection>
              </LinearGradientBrush>
            </ScrollBar.Background>
          </ScrollBar>
        </Grid>
      </Border>
    </ScrollViewer>
    <Border x:Name="FocusVisual" Grid.ColumnSpan="2" Grid.RowSpan="2" AllowDrop="True" BorderBrush="#FFFFC92B" BorderThickness="1, 1, 1, 1" CornerRadius="1, 1, 1, 1" IsHitTestVisible="False" Opacity="0" UseLayoutRounding="False">
      <Border AllowDrop="True" BorderBrush="#00FFFFFF" BorderThickness="1, 1, 1, 1" UseLayoutRounding="False" />
    </Border>
    <ContentControl x:Name="WatermarkVisualElement" AllowDrop="True" BorderThickness="1, 1, 1, 1" FontStyle="Italic" Foreground="#FF000000" HorizontalAlignment="Left" HorizontalContentAlignment="Left" IsHitTestVisible="False" IsTabStop="False" Margin="2, 0, 0, 0" Opacity="0.5" UseLayoutRounding="False" VerticalAlignment="Center" VerticalContentAlignment="Top">
      <Border AllowDrop="True" BorderThickness="1, 1, 1, 1" UseLayoutRounding="False">
        <ContentPresenter AllowDrop="True" UseLayoutRounding="False" />
      </Border>
    </ContentControl>
    <ValidationTooltip x:Name="ValidationTooltip" Grid.ColumnSpan="2" AllowDrop="True" BorderBrush="#FFCB576E" BorderThickness="1, 1, 1, 1" CornerRadius="1, 1, 1, 1" Foreground="#FF000000" IsTabStop="False" UseLayoutRounding="False" Visibility="Collapsed">
      <ValidationTooltip.TooltipContent />
    </ValidationTooltip>
  </Grid>
</RadWatermarkTextBox>

Thanks

2 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 30 Apr 2014, 07:57 AM
Hi Abner,

As the border which you are trying to get is inside txtDatePickerIdle in the visual tree, you have to use ChildrenOfType<Border> (you have to add the following using to your code behind: using Telerik.Windows.Controls; )
In order to get exactly this border, you can use:
var border = this.txtDatePickerIdle.ChildrenOfType<Border>().FirstOrDefault(b => b.Name == "ReadOnlyVisualElement") as Border;
if (border != null)
{
 
}

Hope this helps.

Regards,
Rosen Vladimirov
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Abner
Top achievements
Rank 1
answered on 30 Apr 2014, 09:55 AM
Rose Vladimirov,

Thanks very much, your suggestion really worked.

Abner 
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Abner
Top achievements
Rank 1
Answers by
Rosen Vladimirov
Telerik team
Abner
Top achievements
Rank 1
Share this question
or