标签: uielement

如何在 UIElement 上重置 DesiredSize

我有一个包含任意数量的列表框 UIElement大小未知s。

我希望能够在添加每个项目后跟踪列表框的建议大小。这将允许我将一个大列表(例如:100 个项目)拆分为几个(例如:10)个大致相同视觉效果的较小列表大小,而不管列表中每个元素的视觉大小。

但是,似乎 Measure 传递仅在第一次调用 Measure 时影响ListBoxDesiredSize属性:

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)

size wpf listbox itemscontrol uielement

5
推荐指数
1
解决办法
1564
查看次数

如何在WPF UI中使<UIElement>可交互或可点击

这是我使用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控件的任何/什么属性?

c# richtextbox wpf-controls flowdocument uielement

5
推荐指数
1
解决办法
2361
查看次数

使用装饰器复制UI元素

我正在制作各种尺寸的UI元素(WPF)的屏幕截图,我可以使用"RenderTargetBitmap"实现这一点.但是UIElementAdorner一部分不会在复制时出现.我该怎么做才能实现这一点.任何参考或代码片段?

c# wpf adorner uielement

5
推荐指数
1
解决办法
1675
查看次数

WPF UIElements中的动态TextSize

正如所建议的那样,我允许所有WPF UIElement都具有动态大小,因此可以轻松调整大小,但是,TextBlock我必须指定大小Font.这意味着当元素的大小增加或减少时,字体大小保持不变.有没有办法让Font尺寸变得动态?

c# wpf font-size uielement

4
推荐指数
1
解决办法
4850
查看次数

如何从Silverlight代码背后的UIElement中分离行为?

在Silverlight 3.0中,我UIElement在Code Behind中为某些人添加了自定义行为.

我想稍后在运行时删除行为.

从一个已经添加的行为中删除已经添加的行为的C#语法是UIElement什么?

silverlight silverlight-3.0 uielement

4
推荐指数
1
解决办法
2266
查看次数

将ItemsControl.Items枚举为UIElements

我有一个通过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)

silverlight itemscontrol uielement

4
推荐指数
1
解决办法
2450
查看次数

WPF使用C#从UIElement截取JPG

我正在尝试从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)

c# wpf screenshot wpf-controls uielement

4
推荐指数
1
解决办法
8685
查看次数

在运行时添加和删除WPF UIElements

有没有办法逻辑分组或标记UIElements,如在运行时添加的形状和控件,以便于删除?

例如,我有Grid一些(设计时)子元素,并TextBlock在运行时添加省略号和s.当我想绘制一组不同的椭圆和TextBlocks时,我想删除我添加的原始集.什么是一个简单的方法来逻辑地组合这些添加它们,所以我可以有一个children.clear()或某种方式来识别它们以删除它们?

可以添加标记值,但是在迭代控件的子项时无法检索或读取它,因为它们的类型UIElement没有标记属性.

思考?

wpf uielement

4
推荐指数
1
解决办法
1万
查看次数

从动画完成事件中获取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)

任何帮助将不胜感激.

c# wpf animation casting uielement

4
推荐指数
1
解决办法
2212
查看次数

UIElementCollection和Collection <UIElement>之间的区别?

在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)

如果所有这些都来自一个公共类,并且我在派生类中看不到任何公共(所有这些都是空的!),那么为什么他们首先定义它们呢?我觉得在声明privateinternal派生类中存在一些差异.但我不确切知道.

请帮我理解这些课程的设计.特别是,为什么他们使用它们而不是框架附带的泛型类?有什么好处?

c# collections silverlight wpf uielement

4
推荐指数
1
解决办法
1937
查看次数