我正在尝试在JavaScript中更改SVG元素视图框.基本上,我正在绘制一个二叉搜索树,当它变得太宽时,我想改变视图框以缩小,以便树适合窗口.我目前正在使用:
if(SVGWidth>=1000){
var a = document.getElementById('svgArea');
a.setAttribute("viewbox","0 0 " + SVGWidth + " 300");
}
Run Code Online (Sandbox Code Playgroud)
HTML是:
<svg id="svgArea" xmlns="w3.org/2000/svg"; xmlns:xlink="w3.org/1999/xlink"; width="1000" height="300" viewBox="0 0 1000 300">
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用setAttributeNS('null',...),但这似乎也没有用.我注意到的一件奇怪的事情是,当我发出警报时(a)它给出[对象SVGSVGElement]这看起来很奇怪.任何帮助表示赞赏.
这可能是一个非常简单的问题,但是如何让SVG中的文本拉伸以适应其容器?
我不在乎它是否因拉伸太长或太长而看起来很难看,但它需要适合它的容器并尽可能大.
谢谢
我有一个令人沮丧的问题,我非常感谢一些帮助.我在ViewBox中有一个ListView,我无法让ListView中的项目水平拉伸.
这是XAML:
<Window x:Class="WpfApplication3.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication3"
Title="Window1">
<Window.Resources>
<local:Inning x:Key="inning">
<local:Inning.Skins>
<local:Skin SkinNumber="1"></local:Skin>
<local:Skin SkinNumber="2"></local:Skin>
<local:Skin SkinNumber="3"></local:Skin>
</local:Inning.Skins>
</local:Inning>
</Window.Resources>
<Grid DataContext="{StaticResource inning}">
<Grid.RowDefinitions>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Background="Black"
Text="SKINS"
Foreground="White"
FontSize="80"
FontWeight="Bold"
HorizontalAlignment="Center"></TextBlock>
<Grid Margin="2"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Viewbox>
<ListView Name="lvSkinNumbers"
ItemsSource="{Binding Skins}"
HorizontalAlignment="Stretch"
Background="Black"
VerticalAlignment="Stretch"
VerticalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock FontSize="250"
VerticalAlignment="Stretch"
LineStackingStrategy="BlockLineHeight"
Margin="2"
TextAlignment="Center"
HorizontalAlignment="Stretch"
Background="Black"
Foreground="White"
Text="{Binding SkinNumber}"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Viewbox>
<Viewbox Grid.Column="1">
<ListView Name="lvFirstInningSkins" …Run Code Online (Sandbox Code Playgroud) 我想创建一个仅扩展其高度的Viewbox(或类似的东西),然后水平拉伸其内容.
如果我这样做:
<Viewbox>
<StackPanel>
<Button>Foo</Button>
<Button>Bar</Button>
</StackPanel>
</Viewbox>
Run Code Online (Sandbox Code Playgroud)
然后我明白了:
http://www.excastle.com/misc/viewbox-center.png
它就好像两个按钮都具有HorizontalAlignment ="Center",然后缩放结果.但我不希望HorizontalAlignment ="Center"; 我想要HorizontalAlignment ="Stretch",像这样:
http://www.excastle.com/misc/viewbox-stretch.png
所以我希望它读取其内容的所需高度,仅根据高度计算缩放因子,然后允许缩放内容水平拉伸.
有没有办法使用Viewbox和/或某些第三方面板完成此操作?
我有一个Viewbox,Stretch=Uniform以免扭曲内容.但是,当框架窗口比内容更宽或更高时,Viewbox内容始终居中.
我似乎无法在Viewbox上找到任何内容对齐选项.有没有办法做到这一点?
我有一个TextBlock,其中包含一长串文本,我想要包装.我已经将TextBlock放在ViewBox中,期望文本大小在仍然换行时改变,但是这似乎不会发生.ViewBox只调整TextBox的大小,以便所有文本都适合一行,使文本非常小.
如何在仍使用TextWrapping的同时使用ViewBox调整文本大小.
这是我的代码:
<Viewbox>
<TextBlock Text="The Option text can also dynamically grow/shrink to fit more content. More text to go here....................." TextWrapping="Wrap"/>
</Viewbox>
Run Code Online (Sandbox Code Playgroud)
这是Windows 8商店应用程序的一部分,因此是WinRT Xaml.
我在使用svg时注意到ios上有一个奇怪的东西.svgs似乎在所有其他浏览器中都能正常工作,但在Safari ipad/iphone上,视图框在svg的顶部和底部有一些奇怪的空间.有没有其他人遇到这个,你有没有能够解决它?使用一些简单的svg代码,例如:
<svg width="100%" viewBox="0 0 20 10">
<polygon fill=red stroke-width=0 points="0,10 20,10 10,0" />
</svg>
Run Code Online (Sandbox Code Playgroud)
在ipad/iphone上,如果我在svg上放置一个边框,svg上方和下方都有奇怪的空间......?
小提琴的好看在桌面上看起来很正常,但如果你在ipad等上看它,你会看到问题.
考虑以下:
假设Window是1024x768并且ViewBox填充整个窗口,这意味着TextBox在屏幕上非常大.
我想获得当前在屏幕上的TextBox的大小.如果我得到DesiredSize或ActualSize甚至是RenderedSize,我总是得到100.
有什么建议?
更新:我可能会得到ActualWidthViewBox并将其除以它ActualWidth的子项,这会给我当前的比例因子并以某种方式将其作为属性公开,但我不确定这是最好的方法.
如果我们使用WPF(Silverlight的)Viewbox用Stretch="UniformToFill"或Stretch="Uniform"当它保持内容的原始宽高比,我们怎么能拿知道哪个被应用于内容的缩放的电流系数?
注意:我们并不总是知道内容的确切初始尺寸(例如,它是一个包含大量内容的网格).
在我的应用程序中,我有一个方形按钮网格.每个按钮的文本内容在运行时设置.在大多数情况下,文本只有一个字符长,但有时它更长.我需要使整个文本始终可见,即拉伸它(更改字体大小)以适应按钮的边框.我该怎么做?
我试图使用Viewbox,但它没有帮助.
我的XAML的简化版本:
<Viewbox Stretch="Uniform">
<Button Content="Text"
Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>
</Viewbox>
Run Code Online (Sandbox Code Playgroud)
关于如何实现我需要的任何想法(即方形按钮+总是适合的文本)?
viewbox ×10
wpf ×6
svg ×3
xaml ×2
actualwidth ×1
c# ×1
ios ×1
javascript ×1
layout ×1
listview ×1
safari ×1
silverlight ×1
size ×1
textblock ×1
winrt-xaml ×1
word-wrap ×1
xhtml ×1
xml ×1