Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 元素的布局度量重写不应将正Infinity作为其所需大小返回,即使将Infinity作为可用大小传入_C#_Silverlight_Xaml_Windows Phone 7 - Fatal编程技术网

C# 元素的布局度量重写不应将正Infinity作为其所需大小返回,即使将Infinity作为可用大小传入

C# 元素的布局度量重写不应将正Infinity作为其所需大小返回,即使将Infinity作为可用大小传入,c#,silverlight,xaml,windows-phone-7,C#,Silverlight,Xaml,Windows Phone 7,因此,我试图实现一个简单的Kerning UserControl,用于ListBoxTemplate中的数据绑定文本,我得到了这个报告标题中的错误。几个小时以来,我一直在努力解决这个问题,但运气不佳。当我在VS或Expression Blend中开发时,我使用设计时数据填充数据,但我不确定这是否是它构建时的原因,并且只有在填充数据时才会崩溃 <ListBox x:Name="MainList" ItemsSource="{Binding Fe

因此,我试图实现一个简单的Kerning UserControl,用于ListBoxTemplate中的数据绑定文本,我得到了这个报告标题中的错误。几个小时以来,我一直在努力解决这个问题,但运气不佳。当我在VS或Expression Blend中开发时,我使用设计时数据填充数据,但我不确定这是否是它构建时的原因,并且只有在填充数据时才会崩溃

<ListBox
            x:Name="MainList"
            ItemsSource="{Binding FeedItems}"
            SelectionChanged="ListBox_SelectionChanged"
            >
            <ListBox.ItemTemplate>

                <DataTemplate>
                    <StackPanel Orientation="Horizontal" x:Uid="{Binding ItemLink}" Margin="10">
                        <Controls:KerningTextBlock
                        Spacing="2"
                        Font="Verdana"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Left"
                        FontSize="32"
                        InputText="{Binding ItemTitle}"/>

                ....

明白了…在你必须添加的用户控件中

DataContext="{Binding}"
然后按如下所示设置布局根目录,因为我正在清除LayoutRoot(现在需要将其更改为SubRoot.Children.Clear():

然后在调用用户控件的位置将其更改为:

<Controls:KerningTextBlock
    DataContext="{Binding}"
    Spacing="5"
    Font="Verdana"
    x:Name="Button_Name"
    Margin="135,5,15,0"
    VerticalAlignment="Center"
    HorizontalAlignment="Left"
    FontSize="32"/>


我用你的代码创建项目,一切正常。你能提供更多细节吗:初始化Component()后如何调用KernIt方法等;我调用它。记住我使用的是设计时数据。几秒钟后,你会在UserControl构造函数的字段(输入文本、字体、间距等)中看到整个列表框代码还没有设置。所以您必须在加载的事件中调用您的方法。但是,如果您想在混合中显示一些示例数据,可以将
if(DesignerProperties.IsInDesignTool){Font=“Verdana”;spating=2;InputText=“design”;KernIt();}
添加到构造函数中。
<Grid x:Name="LayoutRoot" >
    <TextBlock x:Name="Title" Text="{Binding ItemTitle}"/>
    <Grid x:Name="SubRoot">
    </Grid>
</Grid>
public KerningTextBlock()
{
    UpdateLayout();
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(KerningTextBlock_Loaded);
}
 void KerningTextBlock_Loaded(object sender, RoutedEventArgs e)
{
     if (string.IsNullOrEmpty(Title.Text))
        this.InputText = "why am I empty?";
    else
        this.InputText = Title.Text;
    KernIt();
}
<Controls:KerningTextBlock
    DataContext="{Binding}"
    Spacing="5"
    Font="Verdana"
    x:Name="Button_Name"
    Margin="135,5,15,0"
    VerticalAlignment="Center"
    HorizontalAlignment="Left"
    FontSize="32"/>