[英][UWP][XAML] not displaying TextBox content
Before posting this issue I have searched and studied alot all answers given on StackOverflow but none did help me, so here I am ^^ 在发布此问题之前,我已经搜索并研究了关于StackOverflow的所有答案,但是没有一个对我有帮助,所以我在这里^^
My goal is to get the corresponsive of a Label in UWP using TextBox. 我的目标是使用TextBox在UWP中获得标签的对应性。
In TextBox property I have set "IsReadOnly="True"" but the "box" was still visible even if its property was set on Transparent. 在TextBox属性中,我设置了“ IsReadOnly =“ True”“,但是即使“ box”的属性设置为“透明”,它仍然可见。
So I have also added "IsEnabled="False"" Property and I have obtained my "label". 因此,我还添加了“ IsEnabled =“ False”“属性,并获得了“标签”。
- -
But, due to project requirements, I needed a white text and not the default-grey-text of uwp. 但是,由于项目要求,我需要白色文本,而不是uwp的默认灰色文本。 So I have tried to set a custom style (following all answers from stackOverflow) until I have found this solution: 因此,我尝试设置自定义样式 (遵循所有来自stackOverflow的答案),直到找到此解决方案为止:
<Style x:Key="Titoli" TargetType="TextBox">
<Setter Property="MinWidth" Value="{ThemeResource TextControlThemeMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource TextControlThemeMinHeight}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="SelectionHighlightColor" Value="{ThemeResource SystemControlHighlightAccentBrush}" />
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="Padding" Value="{ThemeResource TextControlThemePadding}"/>
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="Background" Value="{x:Null}" />
<Setter Property="IsHitTestVisible" Value="False" />
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border x:Name="ContentElement" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And obtaining this Preview (T1,T2,T3 ecc are the labels I am focusing): 并获得此预览(T1,T2,T3 ecc是我正在关注的标签):
But when I'll Debug, the app have this look: 但是当我进行调试时,该应用具有以下外观:
So no textbox is "printed" out... I really can't figure out a solution (Also my custom bottons-images are disappeared!) Any suggestion? 因此,没有“打印”出任何文本框...我真的想不出解决方案(我的自定义bottons图像也消失了!)有什么建议吗?
I have also copy-pasted the full TextBox from here and modified but I can't retrieve the solution in the first screen in this way... 我还从此处复制粘贴了完整的TextBox并进行了修改,但是我无法以这种方式在第一个屏幕中检索解决方案...
code snippet of Xaml.MainPage: Xaml.MainPage的代码段:
<Grid.ColumnDefinitions>
<!--Definisco quante colonne voglio e come siano definite -->
<ColumnDefinition Width="15*"/>
<!-- Colonna per AGGIUNTE SUCCESSIVE -->
<ColumnDefinition Width="15*"/>
<!-- Colonna per Box dati -->
<ColumnDefinition Width="*"/>
<!-- Colonna per il sito a lato -->
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<!--Definisco quante righe voglio e come siano definite -->
<RowDefinition Height="30*"/>
<!-- riga per definire spazio per box dati -->
<RowDefinition Height="15*"/>
<RowDefinition Height="15*"/>
</Grid.RowDefinitions>
<!-- *********************** Sezione display sonde **************************** -->
<!-- Sezione Unità di Misura -->
<TextBox Text="°C" TextWrapping="Wrap" IsEnabled="False" Margin="285,146,374,282" Style="{StaticResource Titoli}" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" HorizontalAlignment="Stretch"/>
<TextBox Text="°C" TextWrapping="Wrap" IsEnabled="False" Margin="567,146,92,282" Style="{StaticResource Titoli}" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" VerticalAlignment="Stretch"/>
<TextBox Text="°C" TextWrapping="Wrap" IsEnabled="False" Margin="285,313,374,115" Style="{StaticResource Titoli}" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" VerticalAlignment="Stretch"/>
<TextBox Text="°C" TextWrapping="Wrap" IsEnabled="False" Margin="567,313,92,115" Style="{StaticResource Titoli}" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" HorizontalAlignment="Stretch"/>
<!-- Sezione Numerazione Sonde -->
<TextBox Text="T1" TextWrapping="Wrap" IsEnabled="False" Margin="278,94,348,308" Style="{StaticResource Titoli}" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="LeftPosition, RightPosition, TopPosition, BottomPosition" VerticalAlignment="Stretch"/>
<TextBox Text="T2" TextWrapping="Wrap" IsEnabled="False" Margin="560,94,66,308" Style="{StaticResource Titoli}" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="TopPosition, BottomPosition" Width="71"/>
<TextBox Text="T3" TextWrapping="Wrap" IsEnabled="False" Margin="278,261,348,141" Style="{StaticResource Titoli}" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="LeftPosition, RightPosition, TopPosition, BottomPosition" HorizontalAlignment="Stretch"/>
<TextBox Text="T4" TextWrapping="Wrap" IsEnabled="False" Margin="560,261,66,141" Style="{StaticResource Titoli}" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="TopPosition, BottomPosition" VerticalAlignment="Stretch" Width="71"/>
<!-- Sezione Valori di Misura -->
---------------EDIT As suggested by @touseefbsb here is the version with TextBlock, but still, none is displayed in Debug... ---------------编辑正如@touseefbsb所建议的那样,这里是TextBlock的版本,但是在Debug中仍然没有显示...
<!-- Sezione Unità di Misura -->
<TextBlock Text="°C" TextWrapping="Wrap" IsTapEnabled="False" Margin="285,146,369,290" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="TopPosition, BottomPosition" Foreground="White" Width="43" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<TextBlock Text="°C" TextWrapping="Wrap" IsTapEnabled="False" Margin="567,146,92,282" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" VerticalAlignment="Stretch" Foreground="White"/>
<TextBlock Text="°C" TextWrapping="Wrap" IsTapEnabled="False" Margin="285,313,374,115" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" VerticalAlignment="Stretch" Foreground="White"/>
<TextBlock Text="°C" TextWrapping="Wrap" IsTapEnabled="False" Margin="567,313,92,115" Height="52" Width="38" FontSize="36" FontFamily="Calibri Light" Grid.Column="1" HorizontalAlignment="Stretch" Foreground="White"/>
<!-- Sezione Numerazione Sonde -->
<TextBlock Text="T1" TextWrapping="Wrap" IsTapEnabled="False" Margin="277,94,357,335" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="LeftPosition, RightPosition, TopPosition, BottomPosition" FocusVisualPrimaryBrush="White" Foreground="White"/>
<TextBlock Text="T2" TextWrapping="Wrap" IsTapEnabled="False" Margin="560,94,66,343" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="TopPosition, BottomPosition" Width="71" FocusVisualPrimaryBrush="White" Foreground="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<TextBlock Text="T3" TextWrapping="Wrap" IsTapEnabled="False" Margin="285,261,344,163" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="HorizontalAlignment, TopPosition, BottomPosition" FocusVisualPrimaryBrush="White" Foreground="White" Width="68" RenderTransformOrigin="0.397,0.913"/>
<TextBlock Text="T4" TextWrapping="Wrap" IsTapEnabled="False" Margin="560,261,66,175" FontSize="48" FontFamily="Calibri Light" Grid.Column="1" d:LayoutOverrides="TopPosition, BottomPosition" Width="71" FocusVisualPrimaryBrush="White" Foreground="White" VerticalAlignment="Stretch"/>
<!-- Sezione Valori di Misura -->
Ok, after @touseefbsb I managed to get a solution. 好的,在@touseefbsb之后,我设法找到了解决方案。
Organizing in Stackpanels and adjusting views with ViewBox in Stretch="Uniform" here is what I have obtained: 在Stackpanels中进行组织并使用Stretch =“ Uniform”中的ViewBox调整视图,这是我所获得的:
<Viewbox Stretch="Uniform">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Sezione Segnali -->
<StackPanel>
<GridView>
....
</GridView>
</StackPanel>
<!-- Sezione Display temperature -->
<StackPanel Grid.Column="1">
<GridView>
<TextBlock x:Name="Sonda_1" TextWrapping="WrapWholeWords" Margin="90 91 -90 10" FontSize="120" FontFamily="Segoi UI" Foreground="White" Width="200" Height="120" />
<TextBlock Text="T1 °C" TextWrapping="WrapWholeWords" Margin="100 100 45 10" FontSize="50" FontFamily="Segoi UI" Foreground="White" Width="55" Height="120" />
<TextBlock x:Name="Sonda_2" TextWrapping="WrapWholeWords" Margin="90 91 -90 10" FontSize="120" FontFamily="Segoi UI" Foreground="White" Width="200" Height="120" />
<TextBlock Text="T2 °C" TextWrapping="WrapWholeWords" Margin="100 100 45 10" FontSize="50" FontFamily="Segoi UI" Foreground="White" Width="55" Height="120" />
</GridView>
<GridView>
<TextBlock x:Name="Sonda_3" TextWrapping="WrapWholeWords" Margin="90 91 -90 10" FontSize="120" FontFamily="Segoi UI" Foreground="White" Width="200" Height="120" />
<TextBlock Text="T3 °C" TextWrapping="WrapWholeWords" Margin="100 100 45 10" FontSize="50" FontFamily="Segoi UI" Foreground="White" Width="55" Height="120" />
<TextBlock x:Name="Sonda_4" TextWrapping="WrapWholeWords" Margin="90 91 -90 10" FontSize="120" FontFamily="Segoi UI" Foreground="White" Width="200" Height="120" />
<TextBlock Text="T4 °C" TextWrapping="WrapWholeWords" Margin="100 100 45 10" FontSize="50" FontFamily="Segoi UI" Foreground="White" Width="55" Height="120" />
</GridView>
</StackPanel>
<!-- Sezione Pulsanti -->
<StackPanel Grid.Row="1">
<GridView>
...
</GridView>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="1">
<GridView>
....
</GridView>
</StackPanel>
<!-- Sezione Loghi -->
<StackPanel Grid.Row="2">
...
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="1">
...
</StackPanel>
</Grid>
</Viewbox>
Hope this helps:) 希望这可以帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.