1

Silverlight 5 では、イメージと Rectangle、Ellipse、Polygon 構造を組み合わせて図面を作成する製品コンフィギュレーターを作成しました。

コンフィギュレーターは問題なく動作し、描画も問題ありません。製品の準備が整うと、ギャラリー (リスト ボックス) に配置され、主要な情報と共に図面のサムネイルが表示されます。ここまでは順調ですね。

ギャラリーに配置された構成をディスク (xml) に保存し、後で読み込んで続行して終了することもできます。これが問題です。コンフィギュレーターに製品を 1 つずつ読み取ります。すべてのビジネス ルールが整っており、図面が作成されます。しかし、製品をギャラリーに保存した瞬間、図面のスナップショットは空白のままです。

製品をギャラリーに配置する前の時点で中断すると、図面が正しく表示されるため、すべての手順が問題ないと確信しています。ただし、ギャラリーでは図面は空白です。したがって、同期/タイミング/更新の問題を想定していますが、画像と描画を含むグリッドを強制的に再描画する方法が見つかりません。

axml では、リストボックス:

<ListBox x:Name="lbTiles" Loaded="lbTiles_Loaded" HorizontalAlignment="left" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Margin="2,2,0,0" Height="233" Width="892" d:LayoutOverrides="HorizontalAlignment" Background="Gainsboro" BorderThickness="2" BorderBrush="#FF606060">
<ListBox.ItemsPanel>
  <ItemsPanelTemplate>
      <StackPanel Orientation="Horizontal"/>
   </ItemsPanelTemplate>
  </ListBox.ItemsPanel>
  <ListBox.ItemTemplate>
      <DataTemplate >
         <StackPanel Orientation="Vertical" Background="Gainsboro">
            <Border BorderThickness="1" BorderBrush="#4F000000" >
              <Grid >
                 <Image Margin="0,0,0,0" Source="{Binding mImage, Mode=OneWay}" Stretch="Uniform" Height="110" ></Image>
              </Grid>
              </Border>
                <TextBox  TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mName, Mode=OneWay}" IsHitTestVisible="False" IsTabStop="False" FontSize="11" />
                <TextBox  TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mPrice, Mode=OneWay}" IsTabStop="False" IsHitTestVisible="False" FontSize="11" />
                 <TextBox  TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mTotal, Mode=OneWay}" IsHitTestVisible="False" IsTabStop="False" FontSize="11" />
                  <TextBox  TextAlignment="Center" IsReadOnly="True" Width="120" Height="23" Text="{Binding mFreight, Mode=OneWay}" IsHitTestVisible="False" IsTabStop="False" FontSize="11" />
                  </StackPanel>
               </DataTemplate>
          </ListBox.ItemTemplate>
      </ListBox>

グリッド:

 <Grid Name="myDrawing" Background="Gainsboro" Height="437" Width="486">
    <Rectangle Name="clrFrame" Visibility="Collapsed" Margin="27,5,32,5" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
       <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL1" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
       <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL0" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
        <Rectangle Name="clrWindow_1" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
         <Rectangle Name="clrWindow_2" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
         <Rectangle Name="clrWindow_3" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
         <Ellipse Name="clrWindow_4" Visibility="Collapsed" StrokeThickness="0" IsHitTestVisible="False" />
          <Polygon Name="clrWindow_5" Visibility="Collapsed" StrokeThickness="18" IsHitTestVisible="False"></Polygon>
          <Rectangle Name="clrDoor" Visibility="Collapsed" Margin="136,196,162,122" StrokeThickness="0" IsHitTestVisible="False" ></Rectangle>
          <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL2" VerticalAlignment="Top" Width="429" IsHitTestVisible="False"/>
          <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL3" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
          <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL4" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
          <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL5" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
           <Image Height="429" HorizontalAlignment="Left" Margin="25.5,4,0,0" Name="imDrawingL6" VerticalAlignment="Top" Width="429" IsHitTestVisible="False" />
      </Grid>

C# コード

for( int i = 0; i < count i++ )
{
xmlread al values to currentCasingComposition.....

writeToScreen(); // apply businessrules and do the drawing
myDrawing.InvalidateMeasure();
myDrawing.InvalidateArrange();
myDrawing.UpdateLayout();
// an exit here leaves me with the product in de confugurator and the drawing is fine
WriteableBitmap bmp = new WriteableBitmap(myDrawing, null); // capture drawing
currentCasingComposition.mImage = bmp;
currentCasingComposition.mImage.Invalidate();
currentCasingComposition.calculatePrice();
    ocCasingCompositions.Add(currentCasingComposition); to gallery via ObservableCollection
}

誰が解決策を知っていますか?

BR、トン

4

1 に答える 1

1

UpdateLayout() は UI スレッドでは非同期であるため、ブロックの残りの部分を呼び出す前に、それが完了するまで待つ必要があります。残念ながら、UpdateLayout() が完了したときに通知を受け取る方法については何も見つかりません。それを参照するすべての例では、DispatcherTimer を使用して、続行する前に 1 秒程度待機します。したがって、1 回限りのディスパッチャー タイマーを作成し、その間隔を 1000 ミリ秒 (または必要に応じてそれ以下) に設定し、Tick イベントで残りのコードを実行します。

于 2013-04-06T13:53:57.940 に答える