我有ControlTemplate一些Paths.我希望Paths伸展并填充它们所处的控制,例如a Button.我怎样才能做到这一点?
我目前看起来像这样:
<ControlTemplate x:Key="SomeTemplate" TargetType="Button">
<Canvas Background="AliceBlue">
<Path Data="M 99.5,50 A 49.5,49.5 0 1 1 0.5,50 A 49.5,49.5 0 1 1 99.5,50 z"
Fill="White" Stroke="Black" StrokeThickness="1" />
<Path Data="M 15,50 C 17.5,22.5 47.5,22.5 50,50 C 52.5,77.5 82.5,77.5 85,50"
Stroke="Black" StrokeThickness="1" />
</Canvas>
</ControlTemplate>
...
<Button Template="{StaticResource SomeTemplate}" Height="120" Width="120" />
Run Code Online (Sandbox Code Playgroud)
我知道ScaleTransform的StrechX和StretchY属性,但它们只有原来的比例缩放Path的尺寸.
我会使用值转换器吗?或者也许某种形式的相对约束父母的大小?
我需要在Border控件(或类似)中绘制一些简单的线条,这些线条始终延伸到Border的边界.有没有办法只拉伸线而不是它的笔?没有涉及大量的C#?
在这个版本中,线条伸展:
<Border>
<Border.Background>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="Red">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0 100,1000" />
<LineGeometry StartPoint="0,0" EndPoint="100,1000"/>
<LineGeometry StartPoint="100,0" EndPoint="0,1000"/>
</GeometryGroup>
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Thickness="20" Brush="Black"/>
</GeometryDrawing.Pen>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>
</Border>
Run Code Online (Sandbox Code Playgroud)
我提出的最佳解决方案是:
<Border>
<Grid>
<Path Stretch="Fill" Fill="Red" Stroke="Black" StrokeThickness="4" Data="M0,0 L100,0 100,1000 0,1000 z" />
<Path Stretch="Fill" Stroke="Black" StrokeThickness="4" Data="M 0,0 L0,0 100,1000" />
<Path Stretch="Fill" Stroke="Black" StrokeThickness="4" Data="M 100,0 L100,0 0,1000" />
</Grid>
</Border>
Run Code Online (Sandbox Code Playgroud)
但是没有更好的解决方案吗?这不涉及额外的网格?
由于速度问题,我不想使用GDI +的DrawImage.还有哪些其他方法来绘制具有良好质量的图像大小 - 至少是线性或三次插值?
我有一个图像,我想用作一些布局的背景.问题是图像包含斜线纹理,所以如果我使用1像素宽度图像或9补丁图像被拉伸,纹理是Twitching,所以我可以看到斜线作为纬度线.我看到他的android模拟器在进度条中使用了类似的纹理不确定动画,是否有一个特殊/简单的定义来命令背景图像重复自己而不是拉伸?有没有办法用9补丁来做,因为最终我也需要圆角.谢谢您的帮助.
我有以下XAML代码:
<Image Source="a.jpg" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform"/>
Run Code Online (Sandbox Code Playgroud)
我在视觉上得到了这个:

(http://img810.imageshack.us/img810/2401/imagestretchuniform.png)
有了Stretch="None",我得到了这个:

(http://img28.imageshack.us/img28/1783/imagestretchnone.png)
现在,我想要的是垂直或水平居中图像Stretch="Uniform"!只有"最小"侧(带Uniform)将居中,右侧.但此刻,你可以在截图看,该图像是简单地把在左上角,即使我定义HorizontalAlignment和VerticalAlignment对"Center"
我该怎么办 ?
整个代码是:
<UserControl [...]>
<Canvas Width="640" Height="480" Background="#FF881607">
<Image Source="a.jpg" HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform"/>
</Canvas>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
编辑(解决方案):以防some1有同样的问题,这是我如何解决它:
<Canvas Width="640" Height="480" Background="#FFAA00FF" >
<Image Source="z.jpg" Height="480" Width="640"/>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
这与HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform"
图像拉伸到均匀(无论图像是否小于或大于画布)的行为完全相同,并且它在垂直和水平方向都居中!
我需要一些帮助使背景图像在线性布局中纵向和横向拉伸或缩放.然而,每次我尝试设置背景时,它都不会拉伸图像以适应屏幕.我也不关心保持纵横比.
这是我目前在测试xml中得到的:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在预览中(以及在游戏中)看起来像这样:

如果我将layout_height更改为fill_parent,我会得到一个重复的背景:
我确信解决方案非常基础,但由于某种原因我错过了它.任何帮助,将不胜感激
谢谢
我正在构建基本的网格系统,需要结合以不同大小单位描述的弹性项目的高度,即%,px和剩余空间.
HTML:
<div class="grid">
<div class="block" style="flex-basis: 50px;">50px</div>
<div class="block" style="flex-basis: 25%;">25%</div>
<div class="block">stretch to remaining space?</div>
<div class="block" style="flex-basis: 50px;">50px</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
html,body,.grid {
height: 100%;
padding: 0;
margin: 0;
}
.grid {
width: 300px;
background: #aaa;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.block {
outline: solid 1px black;
flex-grow: 0; // remove growing proportion
flex-shrink: 0; // remove shrinking proportion
}
Run Code Online (Sandbox Code Playgroud)
我正在创建一个聊天应用.我必须bubble像其他人一样根据文字拉伸图像chatapps.我正在使用AutoLayout约束.包含气泡增加器的imageview的大小完美.(我给它加了黄色背景色).气泡图像没有被拉伸.
我添加了这些约束:
为了拉伸图像我添加了这个:
let myImage = self.imageNamed("Bubble_Me")
let new_Image = myImage.stretchableImage(withLeftCapWidth: 15, topCapHeight: 14)
cell.bubbleImage.image = new_Image
Run Code Online (Sandbox Code Playgroud)
如果有人对此有所了解,请回复.提前致谢.
开发人员.
我尝试在水平方向上拉伸listview项目.我重置了ItemContainerStyle,而horizentalalignment是strech.这是MainPage.xaml中的所有代码.
<Grid x:Name="rootGrid"
HorizontalAlignment="Stretch"
MinWidth="320"
MaxWidth="480"
Width="Auto">
<ListView x:Name="infoFlowListView"
MinWidth="320"
MaxWidth="480"
Width="Auto"
HorizontalAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<local:MyUserControl1 MinWidth="300" HorizontalAlignment="Stretch"></local:MyUserControl1>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这是MainPage.xaml.cs中的所有代码
public MainPage()
{
var items = new List<MyUserControl1>();
for (int i = 0; i < 50; i++)
{
items.Add(new MyUserControl1());
}
this.InitializeComponent();
infoFlowListView.ItemsSource = items;
}
Run Code Online (Sandbox Code Playgroud)
这是MyUserControl.xaml中的所有代码
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="4*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="8"></RowDefinition>
</Grid.RowDefinitions>
<Ellipse Width="60" Height="60"
Grid.Column="0" …Run Code Online (Sandbox Code Playgroud) 看例子:
.container {
background-image:url("http://svgshare.com/i/3cM.svg");
background-position:center center;
background-repeat:no-repeat;
width:400px;
height:200px;
background-color:#eef;
border-bottom:1px solid #000;
background-size:100% 100%;
}Run Code Online (Sandbox Code Playgroud)
<div id="container1" class="container"></div>Run Code Online (Sandbox Code Playgroud)