首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Silverlight MultiScaleImage不会填满可用空间

Silverlight MultiScaleImage不会填满可用空间
EN

Stack Overflow用户
提问于 2010-01-06 15:42:57
回答 2查看 710关注 0票数 3

如果没有明确的宽度和高度,MultiScaleImage甚至不会显示吗?由于某种原因,我不能让它填充网格单元格。它的行为与大多数其他元素不同。

如果我放弃查看器的高度和宽度,它根本不会显示。

编辑:这是完整的图片...XAML:

代码语言:javascript
复制
<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>

相关代码幕后:

代码语言:javascript
复制
[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参数运行):

代码语言:javascript
复制
   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}");
}
EN

回答 2

Stack Overflow用户

发布于 2010-01-10 04:55:28

当我将h/w设置为Auto时,它可以很好地填充Row 0,如下所示:

代码语言:javascript
复制
<MultiScaleImage x:Name="Viewer" Margin="1,1,1,0" Height="Auto" Width="Auto"  />

你甚至可以在Row中加入额外的措施,但我这样做的时候并不需要它:

代码语言:javascript
复制
<MultiScaleImage Grid.Row="0" x:Name="Viewer" Margin="1,1,1,0" Height="Auto" Width="Auto"  /> 
票数 1
EN

Stack Overflow用户

发布于 2010-01-06 17:12:14

尝试更改网格单元定义,如下所示:-

代码语言:javascript
复制
<Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="34" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
    <ColumnDefinition Width=*" />
</Grid.ColumnDefinitions>

对于MultiscaleImage控件来说,为图像指定一个“自然”大小是没有意义的(这将是很大的)。因此,它需要给定大小或伸展到可用大小。您需要在网格行/列定义中使用*,以确保在放置MultiscaleImage控件的单元格位置上传递网格所在控件的剩余可用大小。

编辑

还可以添加

代码语言:javascript
复制
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"

属性添加到MSI控件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2011531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档