天道酬勤,学无止境

xaml

How can I change (i.e. toggle) the bound, StringFormat property of a WPF control?

I have a WPF TextBox that has it's text value bound in XAML. This works fine and, as expected, when the associated value is loaded to the field, it is formatted as desired. My issue is when the user enters the text field to modify the value, I want to strip away the formatting, and display the raw underlying value. To do this, I tried to set the BindingExpression.ParentBinding.StringFormat property, on the text boxes binding from within a GotFocus event. However, when I tried to set the StringFormat property to an empty string, I got the following exception: Binding cannot be changed after it

2021-10-27 03:57:36    分类:问答    c#   wpf   xaml   string-formatting   code-behind

如何为自定义用户控件提供数据触发器属性?(How to give Data trigger property for custom usercontrol?)

问题 我已经将 datagrid 的自定义用户控件创建为 CustomDatagrid。 我在另一个用户控件中使用该自定义数据网格作为 DatagridUserControl。 我在 DatagridUserControl 的 CustomDatagrid 中添加了 Textblock。 我在 DatagridUserControl 中为 Textblock 提供了 x:Name。 <GridControl:CustomDatagrid Grid.Row="2" Height="260" Width="640" x:Name="GridTask" BorderThickness="0" FontSize="24" Foreground="White" SelectionChanged="slmGridTask_SelectionChanged" ColumnWidth="*" CanUserResizeColumns="False" Background="Transparent"> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid Margin="-50,0,0,0" HorizontalAlignment="Left">

2021-10-27 03:37:04    分类:技术分享    c#   wpf   xaml

How to do alternative binding with ControlTemplate in Xamarin Forms

I am using ControlTemplate have consistent Navigation Bar accross Android and iOS <ControlTemplate x:Key="NavBarTemplate"> <StackLayout> <StackLayout Orientation="Horizontal" VerticalOptions="CenterAndExpand" IsVisible="{TemplateBinding BindingContext.IsBackButtonVisible, Mode=TwoWay}"> <Label Text="<" FontSize="Large" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalOptions="FillAndExpand" VerticalTextAlignment="Center" Margin="20,0,0,0" /> <Label TextColor="{StaticResource DarkGrey}" HorizontalOptions="StartAndExpand" HorizontalTextAlignment="Center" VerticalOptions=

2021-10-27 03:22:22    分类:问答    c#   xaml   xamarin.forms   binding   templatebinding

Circular referenced IValueConverter in Application.Resources

I'm getting the error : StaticResource not found for key maxLength the setup is as follows: Converter setup in app.xaml, which also contains a datatemplate <Application.Resources> <ResourceDictionary> <ext:MaxLengthStringConverter x:Key="maxLength"/> .... <DataTemplate x:Key="HotelViewModel"> <tripSegmentPartViews:HotelView Padding="0" HeightRequest="60" BorderWidth="1" BorderColor="{ext:ColourResource Divider}" BordersToDraw="{x:Static controls:Borders.Top}" BackgroundColor="Transparent"/> </DataTemplate> .... view in the HotelView.xaml which is in the datatemplate, uses the converter ....

2021-10-27 03:18:34    分类:问答    xaml   xamarin   xamarin.forms

绑定到对象的 ListView 中的 TextBox,双向绑定不起作用(TextBox inside a ListView bound to an object, two way binding dosen't work)

问题 编辑: 好吧,终于在没有运气的情况下玩了无数次之后,我创建了一个非常小的 Wpf 应用程序。 您可以直接复制此代码。 请注意,当您更改 TextBox 中的值并按下“测试”按钮时,这些值永远不会更新。 我不明白为什么两种方式绑定不起作用。 请帮忙。 这是xaml: <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <ListView Grid.Row="0" ItemsSource="{Binding Path=Demo.CurrentParameterValue,Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center"> <ListView.ItemTemplate> <DataTemplate> <TextBox Text="{Binding Path=.,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="100"></TextBox> </DataTemplate> </ListView.ItemTemplate> </ListView> <Button

2021-10-27 02:34:54    分类:技术分享    c#   wpf   xaml   datatemplate

ScrollViewer keeps snapping back to top

So I have this user control that contains a ListView, wrapped by a ScrollViewer. I set up my layout in the DataTemplate and it's displaying fine, but when you try to scroll down, it just snaps back to the top; it won't hold its position. Here is the xaml: <Border BorderThickness="1" BorderBrush="Black" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Height="80" Width="80" VerticalAlignment="Top"> <Rectangle> <Rectangle.Fill> <ImageBrush Stretch="Fill" ImageSource="{Binding ImageUri}"/> </Rectangle.Fill> </Rectangle> </Border> <TextBlock Grid.Column="1" Grid.Row="0" Style="{StaticResource

2021-10-27 02:25:00    分类:问答    .net   xaml   windows-phone-8.1   scrollviewer

将用户控件与 ViewModel 类关联(Associate User Control with ViewModel class)

问题 当我定义内联DataTemplate ,Visual Studio 知道我要绑定到的类型,并且该类型中的属性会在自动完成中出现(例如,在下面的代码中,我能够从FirstViewModel模板内的自动完成列表中选择DisplayName ) . <DataTemplate DataType="{x:Type viewmodels:FirstViewModel}"> <StackPanel > <Label Content="{Binding DisplayName}"/> </StackPanel> </DataTemplate> <DataTemplate DataType="{x:Type viewmodels:SecondViewModel}"> <views:SecondView/> </DataTemplate> 但是,当数据模板引用外部控件时,如上面代码中的SecondViewModel ,当我在SecondView usercontrol 的文件中时,由于它只是一个控件,因此类型未绑定并且编辑器没有帮助我有什么。 我尝试将我的整个控件(在UserControl元素内)包装在同一个DataTemplate标记中,但是我的整个视图只显示“System.Windows.DataTemplate”。 <UserControl x:Class="Gui.Views.Tabs

2021-10-27 01:27:06    分类:技术分享    wpf   xaml   mvvm

在 MultiSelect ListView (UWP) 中隐藏默认复选框(Hide Default checkbox inside MultiSelect ListView (UWP))

问题 我有一个像这样的 ListView <ListView ItemsSource="{x:Bind DDLItemsSource, Mode=OneWay}" Background="Transparent" VerticalAlignment="Stretch" SelectionChanged="StudentsList_SelectionChanged" x:Name="StudentsList" SelectionMode="Multiple" HorizontalAlignment="Stretch" > <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="BorderThickness" Value="0 0 0 1"/> </Style> </ListView.ItemContainerStyle> </ListView> 当这个 Listview 在页面上呈现时,它在每个项目中都带有默认复选框。 我想隐藏那些复选框并只显示数据。 我怎样才能做到这一点? 这就是 ListView 现在的样子 回答1 在 MultiSelect

2021-10-27 01:22:41    分类:技术分享    xaml   uwp   uwp-xaml

通过依赖属性 (UWP) 更改 VisualState(Change VisualState through Dependency Property (UWP))

问题 我在 UserControl 中有一个文本框,我希望该文本框有两个额外的状态,有效和无效。 我的代码看起来像这样 <UserControl.Resources> <Style TargetType="TextBox" x:Key="ExtendeTextBoxStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="TextBox"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="ValidationState"> <VisualState x:Name="InvalidState"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Stroke"> <DiscreteObjectKeyFrame KeyTime="0" Value="Red" /> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name

2021-10-27 00:15:57    分类:技术分享    c#   xaml   uwp   uwp-xaml

当应用程序运行时,Linux 版 Avalonia UI 中的 DataGrid 不显示(DataGrid in Avalonia UI for Linux does not show up when app is running)

问题 我在 .NET Core for Linux (Fedora) 上运行 Avalonia UI。 我遵循了 DataGrid 的本教程,但老实说,我已经使用以下命令添加了包,而不是手动更新.csproj 。 dotnet add package Avalonia.Controls.DataGrid 在dotnet restore和dotnet run ,我看不到任何 DataGrid。 反正xaml <StackPanel> <DataGrid AutoGenerateColumns="True" Items="{Binding People}"/> </StackPanel> 和 ViewModel 看起来不错。 public ObservableCollection<Person> People { get; } public MainWindowViewModel() { People = new ObservableCollection<Person>(GenerateMockPeopleTable()); } 我怎样才能找到问题所在? 回答1 我忘记在 App.xaml 中应用DataGrid样式(因为我习惯了 Windows 中的 WPF,其中DataGrid是标准控件): <StyleInclude Source="avares://Avalonia

2021-10-26 23:17:21    分类:技术分享    c#   xaml   .net-core   avaloniaui