【问题标题】:WPF Datepicker shows the content of a nearby TextblockWPF Datepicker 显示附近文本块的内容
【发布时间】:2020-07-10 13:20:33
【问题描述】:

有人知道为什么日期选择器会显示附近标签的内容吗?显示的标签位于不同的网格中。当我删除标签文本并将其留空时,将显示网格的下一个标签的文本,依此类推。

无法弄清楚为什么会发生这种情况。一旦我将鼠标悬停在日期选择器上,它就会显示正确的水印。

[编辑] 抱歉,遵循部分代码。

     <StackPanel Grid.Row="1" Grid.Column="0">

        <Grid  Margin="10,10,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <Label Content="Beauftragt durch:"  
                       Grid.Row="0" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <TextBox x:Name="OrderedByEmp"
                       IsEnabled="False"
                       Text="{Binding OrderedByEmpName}"
                       Grid.Row="0" Grid.Column="1" 
                       Width="110" Margin="10,2"
                     />

            <Label Content="Projekt:"  
                       Grid.Row="1" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <TextBox x:Name="Project" 
                     MaxLength="10"
                       Text="{Binding Project}"
                         Grid.Row="1" Grid.Column="1" 
                       Width="110" Margin="0,2"
                     />

            <Label Content="Auftrag:"  
                       Grid.Row="2" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <TextBox x:Name="Order" Text="{Binding Commission}"
                       MaxLength="8"
                       Grid.Row="2" Grid.Column="1" 
                       Width="110" Margin="0,2"
                     />
        </Grid>
    </StackPanel>

    <StackPanel Grid.Row="1" Grid.Column="1">
        <Grid  Margin="10,10,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Label Content="Erstellt am:"  
                       Grid.Row="0" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <TextBox x:Name="OrderDate" Text="{Binding OrderDate, Mode=TwoWay,StringFormat='{}{0:dd.MM.yyyy}'}"
                        IsEnabled="False"
                       Grid.Row="0" Grid.Column="1" 
                       Width="110" Margin="0,2"
                     />
            
            <Label Content="Benötigt bis:"  
                       Grid.Row="1" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <DatePicker x:Name="ExpectedFinishDate" 
                       Grid.Row="1" Grid.Column="1" 
                        Width="110"></DatePicker>

            <Label Content="Abteilung:"  
                       Grid.Row="2" Grid.Column="0" 
                       Width="110" Margin="10,2" />
            <ComboBox x:Name="Departments" Grid.Row="2" Grid.Column="1">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label Content="{Binding Bezeichnung}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </Grid>
    </StackPanel>

    <StackPanel Grid.Column="2" Grid.Row="1">
        <Grid Margin="10,10,2,2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Row="0" Grid.Column="0" 
                       VerticalAlignment="Center" HorizontalAlignment="Right">
                       FLAG:
            </TextBlock>
            <Image Grid.Row="0" Grid.Column="1" Height="20" Source="/Pictures/NotStartetButton.png" />

            <Label Content="Fertiggestellt am:"  
                       Grid.Row="1" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <TextBox x:Name="FinishDatetime" 
                     IsEnabled="False"
                      Grid.Row="1" Grid.Column="1" 
                       Width="110" Margin="0,2"
                     />

            <Label Content="Fertiggestellt durch"  
                       Grid.Row="2" Grid.Column="0" 
                       Width="110" Margin="10,2"
                       HorizontalAlignment="Left" />
            <TextBox x:Name="FinishedByEmp" 
                     IsEnabled="False"
                       Grid.Row="2" Grid.Column="1" 
                       Width="110" Margin="0,2"
                     />
        </Grid>
    </StackPanel>

当我将日期选择器放到另一个位置时,它的工作正常。

现在尝试了几个小时以找出原因......但找不到原因。

感谢您的任何建议!

【问题讨论】:

  • 我们没有任何要检查的代码,所以我们肯定不知道发生了什么。请考虑阅读我们的How to Ask 主题。在您的情况下,我们还需要minimal reproducible example
  • 看起来这是所有您所拥有的代码。但我们需要一个最小可重现的例子。您确定此代码重现您的问题吗?
  • 无法用您提供的代码重现。努力,创建一个单独的项目,尝试重新创建问题。你会学到很多东西。
  • 好吧,去试试。到目前为止谢谢!

标签: wpf datepicker


【解决方案1】:

我尝试在另一个文件中重现该问题,并意识到行为已经改变。愚蠢地我离开了对该问题的进一步研究,因为我认为它位于相关绑定中的任何位置,只是继续稍后再讨论。

但最后我做了很多改变,问题就消失了。

【讨论】:

    猜你喜欢
    • 2015-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多