2014-10-29 47 views
-1

我有一個自定義控件,其中包含一個文本塊,一個組合框和一個超鏈接按鈕。無法禁用自定義控件中的特定文本塊

<UserControl x:Class="IXExpress.Controls.WorkspaceIndexes" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:telerikSdk="http://schemas.telerik.com/2008/xaml/presentation" 
    mc:Ignorable="d" 
    Height="Auto" Width="Auto"> 

    <Grid x:Name="LayoutRoot"> 
     <StackPanel Orientation="Vertical" HorizontalAlignment="Center">       
      <TextBlock x:Name="IndexNameTextBlock" Text="{Binding ApplicationStrings.SelectIndexName, Source={StaticResource ResourceWrapper}, Mode=OneTime}" Margin="3,5" TextAlignment="Left" VerticalAlignment="Center" Visibility="Visible"/> 
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"> 
       <telerikSdk:RadComboBox x:Name="IndexNameCB" 
             DisplayMemberPath="IndexName" 
             HorizontalAlignment="Center" 
             IsDropDownOpen="False" 
             Margin="3,0,3,5" 
             MinWidth="150" 
             Width="150" 
             VerticalAlignment="Center" 
             VerticalContentAlignment="Center" 
             Visibility="Visible" 
             SelectionChanged="IndexNameCB_SelectionChanged"/> 
       <HyperlinkButton x:Name="CreateNewIndexLink" 
           Content="Create New"         
           VerticalContentAlignment="Center" 
           Click="CreateNewIndexLink_Click"/> 
      </StackPanel> 
     </StackPanel> 
    </Grid> 
</UserControl> 

我使用它另一頁上如下:

<StackPanel Orientation="Vertical"> 
    <customControls:WorkspaceIndexes x:Name="WorkspaceIndexes" IsMoreTextRequired="True" Margin="3"/> 
</StackPanel> 

的問題是,在某些條件下,當我想禁用此控制,但它僅禁止組合框和超鏈接按鈕。

代碼:

if (my condition) 
    WorkspaceIndexes.IsEnabled = true; 
    else 
    WorkspaceIndexes.IsEnabled = false; 

結果:

http://imgur.com/L6tbOwo

我還沒有看到 「IndexNameTextBlock」 文本塊的IsEnabled選項,這是爲什麼?

+0

找到了解決方案!由於某些原因,我無法在文本塊中使用IsEnabled屬性,因此我正在自行更改字體顏色。 – CSharper 2014-10-29 18:38:50

回答

1

您看不到TextBlockIsEnabled屬性,因爲它沒有該屬性。其他元素來自Control,它們可以啓用和禁用。 TextBlock不受控制。禁用TextBlock將毫無意義。它只是顯示文字。沒有可能的用戶交互。

如果您需要將其變爲灰色,則必須更改其顏色Foreground或減少其Opacity,或在其上方放置半透明的矩形/邊框。