change the image inside listview DataTemplate In WINRT - winrt-xaml

In windows app (WINRT)i want to change the image dynamically inside the listview,where the listview items are bind by datatemplate

The image is part of your listviewitem template? Could you add an image source path text property of your list items? If you're updating the value dynamically your list items will need to implement INotifyPropertyChanged and raise the PropertyChanged event when the value changes.
<DataTemplate>
<Image Source="{Binding imageSourcePath}" />
</DataTemplate>

Related

Can i creatte a form in a shape specified in the image link below?

I wants to create a form in a specified format where main window area will have some common links or buttons to all pages and the page area is where all the pages will be shown. Is this possible in wpf ?
Yes you can do that by using tab item and frames. You can have an idea using:
<TabItem Header="about" Name="aboutTab">
<TabControl>
<TabItem Header="REGISTRATION" Name="subTabRegistration">
<Grid>
<Frame NavigationUIVisibility="Hidden" VerticalAlignment="Top" HorizontalContentAlignment="Stretch" ClipToBounds="True" JournalOwnership="Automatic" Source="Pages/register-activate.xaml" x:Name="frameRegistration" />
</Grid>
</TabItem>
</TabControl>
</TabItem>

Any idea to create masked text box in uwp

Currently I got a requirement to implement a control something like traditional masked text box. But unfortunately there is no first party control (some third party paid control is available like Component 1) available in uwp. If anybody has any idea to create the same please share.
You can make a TextBox background transparent and have a TextBlock behind it with your watermark text. Bind the visibility to the TextBox Text.IsEmpty property using a BooleanToVisibilityConverter
<Grid Grid.Row="0" Margin="5" Background="White">
<TextBlock VerticalAlignment="Center" Margin="3"
Foreground="SteelBlue"
Visibility="{Binding ElementName=MyTextBox, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}">Type in here...</TextBlock>
<TextBox Background="Transparent"
x:Name="MyTextBox"/>
</Grid>
In your resources:
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
Have a look at PlaceHolderText Property on TextBox control.

How to Update Image on Button Click Command

View has a button and Image control.I have bound the button command to a delegateCommand on the ViewModel, which opens a file dialog for the user to choose an Image.The Context "object" for View contains a property "Icon" which is of type byte[].I have bound the Icon to the Image control.The question is how do i display the selected image file on the image control?.
Xaml:
<Button x:Name="dlgIconbtn" Command="{Binding OpenFileCommand}" Content="Choose Icon" MaxWidth="120" Grid.Row="3" Grid.Column="1" Margin="5"/>
<Image Grid.Row="3" Margin="5" Grid.Column="3" Source="{Binding AppItem.Icon,Converter={StaticResource imgConverter}}"
Width="25" Height="25"/>
I solved it using a property "ImgSource" in the viewModel which is bound to the source of the ImageControl.Whenever a user selects an image using the button command i set the image file contents to the "ImgSource" and it works.
I assume Your Converter is working fine.
Now when OpenFileCommand fires user selects image and you update App.Icon property with new Byte[].
Now please RaiseProperty changed event on Icon so Binding get refreshed.
I do not think you need any Code here.
if still not working then please update you Question with full code XAML + ViewModel

WPF Button in a ListView, how do I tell which button was clicked

WPF 3.5
I have a ListView for which the XAML looks like so
<ListView Name="ListView_FileAttachments">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Header="Type"></GridViewColumn>
<GridViewColumn Header="File Name"></GridViewColumn>
<GridViewColumn Header="Security">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Set Restrictions" Click="Restrictions_Clicked"></Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
When I Click on a button in an individual cell how do I tell which button was clicked ( to be clear though I am interested in the ListView Item that this button belongs to because what I really want to do is retrieve the value of another column in that row )
The DataContext of the button (i.e. the sender for the event) will be the dataitem from the listview's Items. If you want the container (i.e. the ListViewItem) then you can either walk up the visual tree (e.g. using VisualTreeHelper.GetParent) until you hit the ListViewItem or you can use the ListView_FileAttachments.ItemContainerGenerator.ContainerFromItem passing in the data item (which you get from the DataContext of the button).

WPF ListBox ScrollView does not refresh

in our WPF application we have and Listbox with a few items. We temporary need to hide some of the items but since we need to keep the item order we don't remove them. We just set the visibility to collapsed.
This works fine so far but the ScrollViewer of the ListView does not refresh. It is still as long as before and shows some very strange behavior when you try to scroll.
Is there any way to refresh the ScrollViewer when items are collapsed? Or any other was to archive what we have done? Removing the items from the ListView is not an option.
Have you set the ItemContainerStyle? Just like:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Visibility" Value="{Binding Visibility}" />
</Style>
</ListBox.ItemContainerStyle>

Resources