2

Blendをクリックしてグリッドにボタンを配置し、ChangePropertityActionsをいくつか設定すると、エラーメッセージが表示され、失敗します。ButtonコントロールのSilverlight ChangePropertyActionが機能しません

<UserControl 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
x:Class="SL4_Button_States.MainPage" 
Width="640" Height="480"> 

<Grid x:Name="LayoutRoot" Background="White"> 
    <Button x:Name="button" Content="Button" Height="39" Margin="68,42,299,0" VerticalAlignment="Top"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger> 
       <ei:ChangePropertyAction PropertyName="Content" Value="Button is now loaded!" TargetObject="{Binding ElementName=button}"/> 
      </i:EventTrigger> 
      <i:EventTrigger EventName="Click"> 
       <ei:ChangePropertyAction PropertyName="Content" Value="temporary"/> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 
    </Button> 
</Grid> 

エラーメッセージはこれです:あなたはTextBlockの上ChangePropertyActionを追加する場合

Webpage error details 

Message: Unhandled Error in Silverlight Application The type 'Object' was not found. [Line: 2 Position: 10] at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers, Boolean expandTemplatesDuringParse) 
    at MS.Internal.XcpImports.CreateFromXaml(String xamlString, Boolean createNamescope, Boolean requireDefaultNamespace, Boolean allowEventHandlers) 
    at Microsoft.Expression.Interactivity.TypeConverterHelper.ExtendedStringConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value) 
    at Microsoft.Expression.Interactivity.Core.ChangePropertyAction.Invoke(Object parameter) 
    at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter) 
    at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs) 
    at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs) 
    at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args) 
    at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags) 
Line: 1 
Char: 1 
Code: 0 
URI: http://localhost:62193/Silverlight.js 

...正常に動作します:

<TextBlock Height="20" Margin="207,132,138,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger EventName="MouseLeftButtonDown"> 
       <ei:ChangePropertyAction PropertyName="Text" Value="Mouse Left BUtton Down"/> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 
    </TextBlock> 

あなたが任意のアイデアを持っている場合どうしてこのことが起こるのか教えてください...これ以外の/もっと良いやり方があるなら、州以外は私に教えてください知っている。

ありがとうございました。

答えて

3

ButtonのContentプロパティが単なる文字列ではなくオブジェクトなので、失敗しています。ブレンドはそれを設定させても、それが可能であるかどうかはわかりません。

<Button x:Name="button" HorizontalAlignment="Left" Height="23" Margin="154,98,0,0" VerticalAlignment="Top" Width="113"> 
    <Button.Content> 
     <TextBlock x:Name="btnText" Text="Orginal" /> 
    </Button.Content> 
    <i:Interaction.Triggers> 
    <i:EventTrigger> 
     <ei:ChangePropertyAction PropertyName="Text" Value="Loaded" TargetName="btnText"/> 
    </i:EventTrigger> 
    <i:EventTrigger EventName="Click"> 
     <ei:ChangePropertyAction PropertyName="Text" Value="Clicked" TargetName="btnText"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

+0

ありがとうBryant!私は多くのことを暗示していたので、それを知りたいと思っていました。それをどう処理するのか、それを選択できるようにしています...:) – asuciu

0

ボタンのx:名=「ボタン」コンテンツ=「ボタン」高さ=「39」証拠金= "68ボタンのテキストの内容を変更するには、このような何かをする必要があります、42,299,0" をクリック= "button_Click" のMouseRightButtonDown = "button_MouseRightButtonDown" VerticalAlignmentを= "トップ" BlendでChangePropertyAction経由ボタンの内容を変更する方法

private void button_MouseRightButtonDown(object sender, MouseButtonEventArgs e) 

    { 
     ((Button)sender).Content = "Right Click"; 
    } 

    private void button_Click(object sender, RoutedEventArgs e) 
    { 
     ((Button)sender).Content = "Button Click"; 
    } 
+0

あなたのポストマニアに感謝しますが、私はxamlの観点からこれを達成する方法に興味がありました。 :) – asuciu

3

全て以下の手順では、アートボードのボタンを追加します。4.

  1. Expressのブレンドです。アセットの "ChangePropertyAction"をボタン にドラッグします。
  2. データパネルで新しいContentControlデータソースを作成します(「オブジェクトデータソースの作成」をクリックし、「ContentControl」を検索して「OK」をクリックします)、データソースの名前はContentControlDataSourceとなります。
  3. オブジェクトとタイムラインで、ボタンのChangePropertyActionをフォーカスします。 Property-> Common Properties-> PropertyNameで "Content"を選択し、Valueを持つContentControlDataSourceへのデータバインディングを作成します。 「データバインドの作成」ダイアログで、「データフィールドでContentControlDataSource」を選択します。
  4. オブジェクトとタイムラインパネルでは、値の最後に小さい矩形をクリックし、ボタンのChangePropertyActionを再度フォーカスするプロパティ - >共通プロパティ - >値では、 "(ContentControl)New"のようにテキストの周りに黄色の四角形が表示されます。黄色の矩形が消えたら、Valueプロパティの後にNewボタンをクリックします。「オブジェクトの選択」ダイアログが表示されたら、「TextBlock」を検索して追加し、TextBlockのTextを設定します。テキストが設定したものに変更されていることがわかります。

XAMLは次のようになります。

<Button Content="Button" HorizontalAlignment="Left" Margin="125,51,0,0" VerticalAlignment="Top" Width="75"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger EventName="Click"> 
       <ei:ChangePropertyAction PropertyName="Content"> 
        <ei:ChangePropertyAction.Value> 
         <TextBlock Text="HelloText"/> 
        </ei:ChangePropertyAction.Value> 
       </ei:ChangePropertyAction> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 
    </Button> 
関連する問題