2010-12-11 29 views
2

J'essaie d'appliquer le style d'info-bulle sur textboxstyle Dans le contrôle utilisateur. Style que j'ai dans:Style d'info-bulle sur TextBoxStyle {WPF}

<UserControl.Resources> 

<!--Style definition--> 

</UserControl.Resources> 

ToolTipStyle:

<Style x:Key="ToolTipStyle" TargetType="{x:Type ToolTip}"> 
    <Setter Property="Width" Value="200"/> 
    <Setter Property="Height" Value="100"/>   
</Style> 

textboxstyle:

<Style x:Key="textBoxStyle" TargetType="{x:Type TextBox}"> 
     <Setter Property="Width" Value="200"/> 
     <Setter Property="Height" Value="25"/> 
     <Setter Property="FontSize" Value="13"/> 
     <Setter Property="VerticalAlignment" Value="Center"/> 

     <!--Apply toolip style--> 
     <Setter Property="ToolTip.Style" Value="{StaticResource ToolTipStyle}"/> 


     <Style.Triggers> 
      <Trigger Property="Validation.HasError" Value="true"> 
       <Setter Property="ToolTip" 
         Value="{Binding RelativeSource={RelativeSource Self}, 
         Path =(Validation.Errors)[0].ErrorContent}"/> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 

textboxstyle appliquent le champ de saisie constrol:

<TextBox Name="tbNick" 
      Text="{Binding Nick, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" 
      Style="{StaticResource textBoxStyle}"/> 

Je reçois cette compilation d'erreur:

{"Style object is not allowed to affect the Style property of the object to which it applies."}

StackTrace:

at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at Spirit.Views.ShellView.InitializeComponent() in c:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_MEF\Views\ShellView.xaml:line 1 at Spirit.Views.ShellView..ctor() in C:\Users\Jan\Documents\Visual Studio 2010\Projects\C#\Pokec__Messenger\Spirit_MEF\Views\ShellView.xaml.cs:line 9

Appliquer le style de infobulle sur le style textbox n'est pas autorisé à WPF? Ce que je fais mal?

Toujours dans WPF j'utilise caliburn.micro et MEF, mais je pense que cela n'a pas causé cette erreur.

Répondre

8

Un objet de style ne peut pas affecter la propriété Style de l'objet auquel elle applique. Vous pourriez avoir à vérifier ici http://windows-presentation-foundation.com/WPF_Triggers.aspx

vérifierons ce code pour définir le style infobulle

<Grid> 

    <Grid.Resources> 

    <Style x:Key="MyTooltip" TargetType="{x:Type ToolTip}"> 

     <Setter Property = "HorizontalOffset" Value="50"/> 

     <Setter Property = "VerticalOffset" Value="50"/> 

     <Setter Property = "Background" Value="Orange"/> 

     <Setter Property = "Foreground" Value="Red"/> 

     <Setter Property = "FontSize" Value="14"/> 

     <Setter Property = "FontWeight" Value="Bold"/> 

     <Setter Property = "FontFamily" Value="Courier New"/> 

    </Style> 

    </Grid.Resources> 



    <TextBox Margin="10,10,10,10" Height="20"> 

    Pass over with your Mouse 

    <TextBox.ToolTip> 

     <ToolTip Style="{StaticResource MyTooltip}"> 

     <TextBlock>This is the Tooltip</TextBlock> 

     </ToolTip> 

    </TextBox.ToolTip> 

    </TextBox> 

</Grid> 
+0

Merci de l'aide –

10

Il n'y a pas de telle propriété jointe en ToolTip.Style, et le compilateur ne donne pas de description très instructif de l'erreur. Si vous voulez avoir un style personnalisé pour l'utilisation TextBox le style implicite:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Page.Resources> 
     <Style x:Key="textBoxStyle" TargetType="{x:Type TextBox}"> 
     <Style.Resources> 
      <Style x:Key="{x:Type ToolTip}" TargetType="{x:Type ToolTip}"> 
       <Setter Property="Width" Value="200"/> 
       <Setter Property="Height" Value="100"/> 
      </Style> 
     </Style.Resources> 
     <Setter Property="Width" Value="200"/> 
     <Setter Property="Height" Value="25"/> 
     <Setter Property="FontSize" Value="13"/> 
     <Setter Property="VerticalAlignment" Value="Center"/> 
     <Style.Triggers> 
      <Trigger Property="Validation.HasError" Value="true"> 
       <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/> 
      </Trigger> 
     </Style.Triggers> 
     </Style> 
    </Page.Resources> 
    <Grid> 
     <TextBox Name="tbNick" Style="{StaticResource textBoxStyle}" Text="Test" ToolTip="Hey"/> 
    </Grid> 
</Page> 
+0

Merci de l'aide –