InteractionRequest CustomPopupWindow does not resize - wpf

Using a prism Interactionrequest together with a CustomPopUpWindow I have the Problem, that the custom popup window does not resize.
Calling the interaction the first time, it sizes its self to the content correctly, but if I call it again, it kind of memorizes this size and does not change size according to its changed content.
Is this a known issue, or am I doing things wrong?
Regards
Rainer
<i:Interaction.Triggers>
<InteractionRequest:InteractionRequestTrigger SourceObject="{Binding ImportConfirmation, Mode=OneWay}">
<InteractionRequest:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True">
<InteractionRequest:PopupWindowAction.WindowContent>
<Views:ImportMachineDefintionConfirmationView/>
</InteractionRequest:PopupWindowAction.WindowContent>
</InteractionRequest:PopupWindowAction>
</InteractionRequest:InteractionRequestTrigger>
<InteractionRequest:InteractionRequestTrigger SourceObject="{Binding DeleteMachineDefinitionConfirmation, Mode=OneWay}">
<InteractionRequest:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True" >
<InteractionRequest:PopupWindowAction.WindowContent>
<Views:DeleteMachineDefinitionConfirmationView/>
</InteractionRequest:PopupWindowAction.WindowContent>
</InteractionRequest:PopupWindowAction>
</InteractionRequest:InteractionRequestTrigger>
</i:Interaction.Triggers>
private void DeleteMachineDefinitionCommandExecute(IVersionAwareMachineDefinition machineDefinition)
{
var deleteConfirmation =
this.unityContainer.Resolve<IDeleteMachineDefinitionConfirmationViewModel>(
new ParameterOverride("machineDefinitionToDelete", machineDefinition));
this.DeleteMachineDefinitionConfirmation.Raise(
deleteConfirmation,
_ =>
{
if (!_.Confirmed)
{
return;
}
this.repository.DeleteMachineDefinition((MachineType)machineDefinition.MachineTypeId, machineDefinition.MachineNumber);
this.MachineDefinitions =
new ObservableCollection<IVersionAwareMachineDefinition>(this.repository.GetKnownVersionAwareMachineDefinitions());
this.SelectedMachineDefinition = null;
});
}

Related

How to OneWayBind to materialDesign:ButtonProgressAssist.IsIndicatorVisible DependencyProperty

I have a login button that I would like to apply an indeterminate progress look to while the login process is happening.
Here is the XAML for the button:
<Button x:Name="LoginButton" Style="{StaticResource MaterialDesignRaisedButton}"
materialDesign:ButtonProgressAssist.Value="-1"
materialDesign:ButtonProgressAssist.IsIndicatorVisible="false"
materialDesign:ButtonProgressAssist.IsIndeterminate="true">
LOGIN
</Button>
So I figure I can just bind a boolean property on my view model to materialDesign:ButtonProgressAssist.IsIndicatorVisible. I'm using code behind binding like so:
public partial class Connection : ReactiveUserControl<ConnectionViewModel>
{
public Connection()
{
InitializeComponent();
ViewModel = ViewModelLocator.ConnectionViewModel;
this.WhenActivated(d =>
{
this.BindCommand(ViewModel, vm => vm.LoginCommand, v => v.LoginButton).DisposeWith(d);
// How do I bind to this property using OneWayBind?
this.OneWayBind(ViewModel, vm => vm.LoggingIn, v => v.LoginButton.ButtonProgressAssist.IsIndicatorVisible).DisposeWith(d);
});
}
}
Intellisense doesn't pick up on that material designs dependency property. How do I reference it?
In case it matters, the WPF project targets .NET Core 3.1
I don't think the OneWayBind method supports attached properties but you could bind to it in the XAML markup:
materialDesign:ButtonProgressAssist.IsIndicatorVisible="{Binding LoggingIn, Mode=OneWay}"
You can of course do OneWayBind for the other properties just like before.

Updating telerik:RadPieChart Palette asynchronously doesn't work

As the title suggests I'm trying to update the Palette of the telerik:RadPieChart asynchronously. I have implemented a Task which tries to check for new records at a given interval and updates the UI if there's any. Every other controls are updating correctly except the Palette of the telerik:RadPieChart. The Palette would disappear after the Task tries to update it. Here is the pie chart I'm working with.
<telerik:RadPieChart Name="PieLinearChart" Foreground="Gainsboro" FontSize="12" FontWeight="Black" Grid.Row="0" Palette="{Binding Tab.CurrentPoC.PalettePie1}" Height="50px">
<telerik:RadPieChart.Series>
<telerik:DoughnutSeries ShowLabels="True" InnerRadiusFactor="0.4" ValueBinding="Sum" ItemsSource="{Binding Tab.CurrentPoC.PieChart1, Mode=TwoWay}" />
</telerik:RadPieChart.Series>
</telerik:RadPieChart>
The telerik:DoughnutSeries values are updating, though.
The code behind looks something like this:
public Task Init()
{
.......
.......
ExchangeFile.DataUpdated += Exchange_DataUpdated;
.......
.......
}
//This method was called every certain interval
//and works from the background.
private void Exchange_DataUpdated()
{
......
......
//Setting colors to the Palette
//which didn't work in this case
//(works well for other situations)
PalettePie1 = new ChartPalette();
ChartPalette tmpPalette = new ChartPalette();
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Red")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Blue")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Yellow")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Green")));
PalettePie1 = tmpPalette;
......
}
I also tried something like this but didn't help:
Application.Current.Dispatcher.Invoke(new Action(() => {
......
ChartPalette tmpPalette = new ChartPalette();
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Red")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Blue")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Yellow")));
tmpPalette.GlobalEntries.Add(new PaletteEntry(Utilities.NvarBrushUtils.GetBrush("Green")));
PalettePie1 = new ChartPalette();
PalettePie1 = tmpPalette;
......
}));
Please help!

Get content of Checkbox with Hyperlink as content

This is an example of how I make my checkboxes:
<CheckBox x:Name="Ekm" Checked="Check" Unchecked="UnCheck">
<CheckBox.Content>
<TextBlock>
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="[REDACTED]">
Banking History
</Hyperlink>
</TextBlock>
</CheckBox.Content>
</CheckBox>
And the code-behind:
foreach (var checkbox in listview.Items)
{
if (checkbox is CheckBox cb)
{
if (cb.Name.StartsWith("Sa"))
{
SelectAllCheckBoxes.Add(cb);
}
else
{
AllCheckBoxes.Add(cb);
}
}
}
And the moment I try to read the content (Specifically the words "Banking History"):
foreach (var cb in AllCheckBoxes)
{
NameCompareTuples.Add(new Tuple<string, string>(cb.Name, cb.Content.ToString()));
}
The above code, and many variations I've tried (Casting as TextBlocks and such, thus not needing ".ToString();"), simply return an empty string, or if I apply ".ToString();" it passes something along the lines of:
"System.Windows.Controls.TextBlock"

F# wpf async command completion status

I've been experimenting with async commands using F# Viewmodule. The problem is when I click the button, the command get executed, but afterwards the button stays disabled.
Xaml:
<Button Content="start async worker" Command="{Binding StartAsyncCommand}" />
ViewModel:
type MainViewModel() as me =
inherit ViewModelBase()
//...
member __.StartAsyncCommand = me.Factory.CommandAsync(fun _ -> async { return () } )
What am I doing wrong?
EDIT:
Thanks to #FoggyFinder, we determined that the issue was actually with the App.fs file:
open System
open FsXaml
open System.Windows
type MainWindow = XAML< "MainWindow.xaml">
[<STAThread>]
[<EntryPoint>]
let main argv =
Application().Run(MainWindow().Root)
Creating basically empty App.xaml and starting like this:
module main
open System
open FsXaml
type App = XAML<"App.xaml">
[<STAThread>]
[<EntryPoint>]
let main argv =
App().Root.Run()
fixed it. If anyone knows the explanation for this, don't hesitate to provide it.
What am I doing wrong?
The problem is that there is no SynchronizationContext in place when you construct your ViewModel layer, which means that the internal code that pushes things back to the UI context don't work properly.
You can work around this by adding the following at the beginning of your entry point, before you call Application.Run():
if SynchronizationContext.Current = null then
DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher)
|> SynchronizationContext.SetSynchronizationContext
This will make sure the Dispatcher is created and a valid SynchronizationContext is installed, and will likely fix the issue for you.
I used asynchronous commands, but this problem never arose. I tried to reproduce your code - everything is working fine. Are you sure you gave complete code?
Try to run the code:
.xaml:
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<Button Content="start async worker" Command="{Binding StartAsyncCommand}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" />
<TextBlock Text="{Binding Count}" Margin="5" HorizontalAlignment="Right" VerticalAlignment="Top"></TextBlock>
</Grid>
ViewModel:
type MainViewModel() as me =
inherit ViewModelBase()
let count = me.Factory.Backing(<# me.Count #>, 0)
member __.StartAsyncCommand = me.Factory.CommandAsync(fun _ -> async { count.Value <- count.Value + 1 })
member __.Count with get() = count.Value
About the differences between
let dosomething _ = async { return () }
member __.StartAsyncCommand = me.Factory.CommandAsync(dosomething)
and :
member __.StartAsyncCommand = me.Factory.CommandAsync(fun _ -> async { return () } )
look this answer:
https://chat.stackoverflow.com/transcript/message/26511092#26511092
The easy workaround is to use interaction triggers:
<Button>
<ia:Interaction.Triggers>
<ia:EventTrigger EventName="Click">
<fsx:EventToCommand Command="{Binding StartAsyncCommand}" />
</ia:EventTrigger>
</ia:Interaction.Triggers>
</Button>

How to select all checkBoxes in LongListMultiSelector WP8

How can i select all the checkBoxes in LongListMultiSelector on click of a ApplicatonBar's ApplicationBarMenuItem. This feature is same as messaging app of wondows phone.
I reffered
Click here
but no use.
my code:
<toolkit:LongListMultiSelector x:Name="requestList"
EnforceIsSelectionEnabled="False">
<toolkit:LongListMultiSelector.ItemTemplate>
<DataTemplate>
<TextBlock x:Name="requestNameTxtblk"
Text="{Binding request}"
TextWrapping="Wrap" HorizontalAlignment="Left"
Width="268" Height="66" FontSize="25"/>
</DataTemplate>
</toolkit:LongListMultiSelector.ItemTemplate>
</toolkit:LongListMultiSelector>
Thanks
Can you just iterate over the requestList's ItemsSource and mark the items as selected:
(note this code is not tested, just a guess for now):
foreach (var item in requestList.ItemsSource)
{
item.Selected = true;
}
Or similar?
Hi guys got the solution
foreach (var item in requestList.ItemsSource)
{
requestList.SelectedItems.Add(item);
}
this will check all the checkBox in the list and to uncheck all the box
Remove() method can be used as add()

Resources