2010-01-06 73 views
3

是我還是MultiScaleImage甚至沒有顯式寬度和高度顯示?出於某種原因,我無法填充網格單元格。它的行爲與大多數其他元素不同。Silverlight MultiScaleImage不會填充可用空間

如果我在查看器上放棄高度和寬度,它根本不顯示。

編輯:下面是完整的圖片... XAML:

<UserControl x:Class="CliqueSite.DeepZoom.Viewer.ZoomPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
<Grid x:Name="LayoutRoot" Background="Black"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*" /> 
     <RowDefinition Height="34" /> 
    </Grid.RowDefinitions> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
    </Grid.ColumnDefinitions> 
    <MultiScaleImage x:Name="Viewer" Margin="1,1,1,0" Height="675" Width="900" /> 
    <Rectangle Grid.Row="1"> 
     <Rectangle.Fill> 
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
       <GradientStop Color="#FF000000"/> 
       <GradientStop Color="#FF808080" Offset="1"/> 
      </LinearGradientBrush> 
     </Rectangle.Fill> 
    </Rectangle> 
    <Button HorizontalAlignment="Right" Margin="0,0,4,4" VerticalAlignment="Bottom" Padding="6" Grid.Row="1" 
      Content="Zoom Reset" x:Name="ZoomReset" FontSize="9" FontFamily="Verdana" /> 
</Grid> 

相關的代碼背後:

[ScriptableMember] 
public void SetSource(int width, int height, int tileSize, int id, string urlToFormat) 
{ 
    Viewer.Source = new ViewerSource(width, height, tileSize, id, urlToFormat); 
    double x = 0; 
    double y = 0; 
    double w = 1; 
    if ((width > height && Viewer.Width > Viewer.Height) || (width > height && Viewer.Width < Viewer.Height)) 
    { 
     double scaleFactor = Viewer.Width/width; 
     double adjustedHeight = height * scaleFactor; 
     double topSpace = (Viewer.Height - adjustedHeight)/2; 
     y = -(topSpace/Viewer.Height) * (Viewer.Height/Viewer.Width); 
    } 
    else 
    { 
     double scaleFactor = Viewer.Height/height; 
     double adjustedWidth = width * scaleFactor; 
     w = Viewer.Width/adjustedWidth; 
     double leftSpace = (Viewer.Width - adjustedWidth)/2; 
     x = -(leftSpace/Viewer.Width) * w; 
    } 
    _viewportOrigin = new Point(x, y); 
    _viewportWidth = w; 
    ResetZoom(); 
} 

Javascript代碼(從嵌入對象的onload PARAM運行):

function LoadImage() { 
    var viewer = $("#DeepZoomViewer")[0]; 
    viewer.content.Bridge.SetSource(<%= Model.ZoomProperties.Width %>, <%= Model.ZoomProperties.Height %>, 256, <%= Model.Photo.ID %>, "http://localhost:7070/TileHandler.ashx?id={0}&level={1}&x={2}&y={3}"); 
} 
+0

編輯我的答案。 – AnthonyWJones 2010-01-08 08:24:28

+0

如果確實如此,我會將其標記爲答案。 – 2010-07-09 17:15:02

回答

0

嘗試更改網格單元定義如下: -

<Grid.RowDefinitions> 
    <RowDefinition Height="*" /> 
    <RowDefinition Height="34" /> 
</Grid.RowDefinitions> 
<Grid.ColumnDefinitions> 
    <ColumnDefinition Width=*" /> 
</Grid.ColumnDefinitions> 

它不爲MultiscaleImage控制到指定圖像的「自然」大小(這將是巨大的)意義。因此,它期望得到大小或延伸到可用的大小。您需要使用*在網格行/列的定義,以確保在電網是地方上的MultiscaleImage控件放置在小區的位置是通過控制的剩餘可用大小。

編輯

另外補充

VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 

屬性到MSI控制。

+0

不......這裏沒有快樂。我確信你是對的,但MSI仍然沒有高度或寬度。 – 2010-01-08 03:10:18

+0

不...沒有變化。如果我將文本塊綁定到寬度,它總是顯示0: 2010-01-08 22:55:29

1

它填補行0對我就好了,當我設置H/W爲Auto,這樣的:

<MultiScaleImage x:Name="Viewer" Margin="1,1,1,0" Height="Auto" Width="Auto" /> 

你甚至可以扔在行額外的措施,但它並不需要我的時候做到了這一點:

<MultiScaleImage Grid.Row="0" x:Name="Viewer" Margin="1,1,1,0" Height="Auto" Width="Auto" /> 
+0

工作。我的問題必須得到更深入的研究。我有一個Javascript調用來設置圖像源(通過橋),設置爲觸發對象的onload參數。再說一遍,當我有一個明確的高度/寬度設置。 – 2010-01-10 07:35:01

+0

請考慮發佈更多代碼,包括js調用和其他可能有助於重現問題的項目。 – 2010-01-10 09:04:05