我有一个包含任意数量的列表框 UIElement
大小未知s。
我希望能够在添加每个项目后跟踪列表框的建议大小。这将允许我将一个大列表(例如:100 个项目)拆分为几个(例如:10)个大致相同视觉效果的较小列表大小,而不管列表中每个元素的视觉大小。
但是,似乎 Measure 传递仅在第一次调用 Measure 时影响ListBox
的DesiredSize
属性:
public partial class TestWindow : Window
{
public TestWindow()
{
InitializeComponent();
ListBox listBox = new ListBox();
this.Content = listBox;
// Add the first item
listBox.Items.Add("a"); // Add an item (this may be a UIElement of random height)
listBox.Measure(new Size(double.MaxValue, double.MaxValue)); // Measure the list box after the item has been added
Size size1 = listBox.DesiredSize; // reference to the size the ListBox "wants" …
Run Code Online (Sandbox Code Playgroud) 这是我使用WPF设计UI的第一天.我查找了Flow Document的 MSDN官方文档,发现我可以在RichTextBox中放置一个UI控件.我确实放了一个按钮,但发现它不能互动 - 我不能点击它,因为它是灰色的.我也尝试了其他控件,它们都显示正常但只是不支持交互.即使是超链接也不起作用.
我通过互联网搜索,有史以来最接近的问题是关于如何使内部超链接可点击:类似的问题:C#WPF文本链接
我做了同样的事情,但没有奏效!所有组件都显示良好,但无法单击.
这是我的XAML代码:
<RichTextBox Grid.Row="1" Margin="14.007,31.067,22.011,46.305" Name="rtxtRslt" BorderBrush="White" >
<FlowDocument>
<Section FontSize="15">
<Paragraph>
<Bold>Click on this:</Bold>
<Italic><Hyperlink NavigateUri="http://stackoverflow.com">http://www.jxitc.info</Hyperlink></Italic>
</Paragraph>
<BlockUIContainer>
<Button Click="Button_Click">Also Click On This</Button>
</BlockUIContainer>
</Section>
</FlowDocument>
</RichTextBox>
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我一些建议:1.是否有可能使其可点击2.如果是,如果我忘记设置RichTextBox控件的任何/什么属性?
我正在制作各种尺寸的UI元素(WPF)的屏幕截图,我可以使用"RenderTargetBitmap"实现这一点.但是UIElement
有Adorner
一部分不会在复制时出现.我该怎么做才能实现这一点.任何参考或代码片段?
正如所建议的那样,我允许所有WPF UIElement
都具有动态大小,因此可以轻松调整大小,但是,TextBlock
我必须指定大小Font
.这意味着当元素的大小增加或减少时,字体大小保持不变.有没有办法让Font
尺寸变得动态?
在Silverlight 3.0中,我UIElement
在Code Behind中为某些人添加了自定义行为.
我想稍后在运行时删除行为.
从一个已经添加的行为中删除已经添加的行为的C#语法是UIElement
什么?
我有一个通过a显示的超链接列表ItemsControl
,如下所示:
<ItemsControl x:Name="SubMenu" Visibility="Collapsed">
<ItemsControl.ItemTemplate>
<DataTemplate>
<HyperlinkButton Content="{Binding Name}"
NavigateUri="{Binding Url}"
TargetName="ContentFrame"
Style="{StaticResource LinkStyle}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Style="{StaticResource LinksStackPanelStyle}"
VerticalAlignment="Center"
HorizontalAlignment="Left" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)
我需要做的是枚举子菜单中的实际超链接,如下所示:
foreach (UIElement child in SubMenu.Items) // this does not work!
{
HyperlinkButton hb = child as HyperlinkButton;
if (hb != null && hb.NavigateUri != null)
{
if (hb.NavigateUri.ToString().Equals(e.Uri.ToString()))
{
VisualStateManager.GoToState(hb, "ActiveLink", true);
}
else
{
VisualStateManager.GoToState(hb, "InactiveLink", true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我似乎找不到枚举ItemsCollection.Items中实际UI元素的方法.
任何人都知道如何做到这一点或可能的解决方法?
我可以提一下,我想要做的是建立一个菜单和子菜单,显示点击的超链接作为一种面包屑.
更新: 最好的事情是,如果我能以某种方式到达该stackpanel,因为这段代码似乎工作:
foreach (UIElement child …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从WPF应用程序的一部分创建JPG.就像截图一样,只有个人UIElement
的.我从这里开始:http://www.grumpydev.com/2009/01/03/taking-wpf-screenshots/
我正在使用他的扩展方法,这个方法允许你得到一个byte [] UIElement.GetJpgImage()
.然后可以使用文件流将其写入JPG图像.如果我制作整个窗口的JPG,它看起来很好!但是,这并不理想,因为它只捕获用户看到的内容.因滚动查看器而无法显示的内容或因为其父级动画为小尺寸而无法显示的内容.
如果我拍摄一个"截图",例如我用于布局的网格: alt text http://img697.imageshack.us/img697/4233/fullscreenshot2.jpg
我得到了这个黑色背景的垃圾.我不希望这样.此外,如果我使用动画折叠了这个网格的高度,我根本不会得到任何东西.这些实际上是模板化的复选框,它们上面应该有黑色文本,网格的背景应该是白色的.以下是其他人编写的代码,用于返回写入文件流的byte []数组:
public static byte[] GetJpgImage(this UIElement source, double scale, int quality)
{
double actualHeight = source.RenderSize.Height;
double actualWidth = source.RenderSize.Width;
double renderHeight = actualHeight * scale;
double renderWidth = actualWidth * scale;
RenderTargetBitmap renderTarget = new RenderTargetBitmap((int) renderWidth, (int) renderHeight, 96, 96, PixelFormats.Pbgra32);
VisualBrush sourceBrush = new VisualBrush(source);
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
using (drawingContext)
{
drawingContext.PushTransform(new ScaleTransform(scale, scale));
drawingContext.DrawRectangle(sourceBrush, null, …
Run Code Online (Sandbox Code Playgroud) 有没有办法逻辑分组或标记UIElements,如在运行时添加的形状和控件,以便于删除?
例如,我有Grid
一些(设计时)子元素,并TextBlock
在运行时添加省略号和s.当我想绘制一组不同的椭圆和TextBlock
s时,我想删除我添加的原始集.什么是一个简单的方法来逻辑地组合这些添加它们,所以我可以有一个children.clear()或某种方式来识别它们以删除它们?
可以添加标记值,但是在迭代控件的子项时无法检索或读取它,因为它们的类型UIElement
没有标记属性.
思考?
从我的代码隐藏开始,我想在特定的动画上开始动画UIElement
,当动画结束时,我想对其进行一些其他的处理UIElement
.我无法弄清楚如何将AnimationClock
我作为动画完成事件的发送者接收的对象转换UIElement
为执行动画的对象.
这是我用来构建和启动动画的代码:
DoubleAnimation FadeOutAnim = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(.5));
FadeOutAnim.Completed += new EventHandler(FadeOutAnim_Completed);
UIElement element = lstMessages.ItemContainerGenerator.ContainerFromItem(sender) as UIElement;
if(element != null)
element.BeginAnimation(UIElement.OpacityProperty, FadeOutAnim);
Run Code Online (Sandbox Code Playgroud)
这是我完成的活动,我希望UIElement
再次访问.
void FadeOutAnim_Completed(object sender, EventArgs e)
{
UIElement animation = sender; //This is an AnimationClock and I can't seem to figure out how to get my UIElement back.
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
在WPF和Silverlight中,我们看到了以下类:
UIElementCollection
ItemCollection
RowDefinitionCollection
ColumnDefinitionCollection
PointCollection
为什么他们有这些类,每种类型一个类?为什么他们不使用泛型类Collection<T>
?
另外,我在Silverlight中看到,所有这些类都来源于PresentationFrameworkCollection<T>
,as
public sealed class ItemCollection : PresentationFrameworkCollection<Object>
public sealed class PointCollection : PresentationFrameworkCollection<Object>
public sealed class IconCollection : PresentationFrameworkCollection<Object>
//and so on...
Run Code Online (Sandbox Code Playgroud)
如果所有这些都来自一个公共类,并且我在派生类中看不到任何公共(所有这些都是空的!),那么为什么他们首先定义它们呢?我觉得在声明private
或internal
派生类中存在一些差异.但我不确切知道.
请帮我理解这些课程的设计.特别是,为什么他们使用它们而不是框架附带的泛型类?有什么好处?
uielement ×10
wpf ×7
c# ×6
silverlight ×3
itemscontrol ×2
wpf-controls ×2
adorner ×1
animation ×1
casting ×1
collections ×1
flowdocument ×1
font-size ×1
listbox ×1
richtextbox ×1
screenshot ×1
size ×1