Hi! Sorry I don't understand. Can you please explain what you mean?
Mc_Topaz
Posts
-
Animation on DataGridRow jumps to wrong row when scrolling -
Animation on DataGridRow jumps to wrong row when scrollingI have a DataGrid where we display an animation on DataGridRows when a property in the ItemSource is set. If the height of the DataGrid is enough low to display the VerticalScrollBar, I can scroll up and down and see the animations jump to the wrong rows. I have made code snippet that reproduce the issue: * The code shuld be "copy-paste". * The DataGrid displays a list of Persons. * If a person's
HasBirthday = true
the corresponding DataGridRow displays the animation. * The first item in the list hasHasBirthday = true
. To reproduce 1) Notice the first row has the animation running already. 2) Click the second row in the Grid. 3) Scroll down. 3) Some other row should now also have the animation on it. Scrolling up and down a couple of times should also diplay the issue. * Any explanation why this happens? * Any suggestions how to fix this? /BR Steffe XAML<Setter Property="Foreground" Value="Blue" /> <Setter Property="Background" Value="LightGray" /> <Setter Property="MinHeight" Value="26" /> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="Gray" /> </Trigger> </Style.Triggers> <Style.Triggers> <MultiData</x-turndown>
-
Impossible to override a value in an animation located in a style?I have a style
FooStyle
with some properties and an animation. I have two other stylesBar1Style
andBar2Style
which is based on theFooStyle
and sets some properties. I would like to alter the the values in the animation for the Bar-styles. In the animation I'm altering the buttons ScaleX and ScaleY values with the MouseIsOver trigger. In the code bellow you notice the valuesFrameOneValue
andFrameTwoValue
.<Style.Resources> <system:Double x:Key="FrameOneValue">1.0</system:Double> <system:Double x:Key="FrameTwoValue">1.05</system:Double> </Style.Resources> <Setter Property="FontWeight" Value="Bold" /> <Setter Property="RenderTransformOrigin" Value="0.5 0.5" /> <Setter Property="RenderTransform"> <Setter.Value> <TransformGroup> <ScaleTransform/> </TransformGroup> </Setter.Value> </Setter> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)\[0\].(ScaleTransform.ScaleX)"> <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="{DynamicResource FrameOneValue}"/> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="{DynamicResource FrameTwoValue}"/> </DoubleAnimationUsingKeyFrames> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)\[0\].(ScaleTransform.ScaleY)"> <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="{DynamicResource FrameOneValue}"/> <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="{DynamicResource FrameTwoValue}"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(Transfor</x-turndown>
-
Override a value in base style's resourceThank you! I got it to work in my example application. But in my real application fail hard. I'll make a new post about it.
-
Override a value in base style's resourceI have two style
FooStyle
andBarStyle
. I also have three TextBlocks and two of them use the styles above. In theFooStyle
I have specified adouble
(theWid
parameter) that is used to set the Width of the TextBlock (txt2) to 20. In theBarStyle
I would like to use theFooStyle
but override the Wid parameter with the value 40 on the TextBlock (txt3). But the txt3 TextBlock's Width don't get a longer Width. It still has the same Width as txt2. Here is my code<Style.Resources> <sys:Double x:Key="Wid">20</sys:Double> </Style.Resources> <Setter Property="Width" Value="{StaticResource Wid}" /> <Setter Property="FontWeight" Value="Bold" /> <Style.Resources> <sys:Double x:Key="Wid">40</sys:Double> </Style.Resources>
Is it possible to overwrite the Wid parameter in the BarStyle?
-
[Updated] Attached Properties to UserControlI have a UserControl which a bunch of Controls. In the UserControl there is TextBlock displaying a text as a title. The title is implemented as a DepedencyProperty in my UserControl and I can easily set the TextBlock's value in the MainWindow's XAML code. Like this:
Notice my custom
Title
property. I also have a button (Button1) in the UserControl with some properties. I want to specify the button's properties in the MainWindow XAML-code. But I don't manage to gain access to the buttons properties in the XAML-code if I use a similar Dependency property. I want this:As you see I'm interesting to group the Button1's properties and be able to set its properties in the MainWindow's XAML-code. But with no success :sigh: Here is the code for the
MyUserControl
of what I have tried:public class MyButton: FramworkElement
{
public ICommand Command { get; set; }
public string Header { get; set; }
}public class MyUserControl : UserControl
{
public static readonly DependencyProperty Button1Property = DependencyProperty.RegisterAttached
(
"Button1",
typeof(MyButton),
typeof(MyUserControl),
new FrameworkPropertyMetadata(false, new PropertyChangedCallback(Button1Changed))
);public MyButton Button1 { get { return (MyButton)GetValue(Button1Property); } set { SetValue(Button1Property, value); } } public static void Button1Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { // ToDo }
}
I found this weird because this kinda works when enclosing a control in a DockPanel.
DockPanel.Dock="Left"
-
Impossible? Get instance of MainWindow from extern WPF-application:doh: Why didn't I thought of that. I tried it yesterday and it worked great. Thanks!
-
Impossible? Get instance of MainWindow from extern WPF-applicationIt might be time to tell the my idéa. B is a WPF-application my company has. We don't have any unit test for the GUI of B. We want that. So I thought if: * B is a WPF-project in our Visual Studio solution. * A is a unit test project in the same solution. * A has some "code/package/NuGet" to start, terminate B and gain access of all public controls in B. * In A we write the unit tests that use the "code/package/NuGet" to access the controls in B to do our unit tests. For instance if I want to test a button's click event in B: 1) In A: Run a specific test case. 2) In A: Start B. 3) In A: Someway gain access of all public controls of B. 4) In A: Put a text in a TextBox located in B. 5) In A: Trigger the click event of a Button located in B. 6) In B: The Button's click event puts the TextBox's text in a TextBlock. 7) In A: Read the Text from the TextBlock inside of B. 8) In A: Verify the text and pass or fail the test. 9) In A: Terminate B. I have looked at Appium with the WinAppDriver solution. That works, but it requires the WinAppDriver application running in the background to handle all communications between A and B. I don't want a third party or be forced to write any IPC in B. Unit test should be easy to write and run. If each develop must install the WinAppDriver to run tests, it's just tedious. However, I like the way that WinAppDriver use the
AutomationProperties.AutomationId
and other properties on controls to allow "A" to access it "B". I would like a similar solution. @Gerry Schmitz How should I do to instantiate B in A? If that give me access to all public controls, that will be fine! Best regards, /Steffe -
Impossible? Get instance of MainWindow from extern WPF-applicationI did wait so the MainWindow/Process of B had shown up before I ran the GetB() method. But it didn't matter that I waited... I don't want to alter the B WPF-application. Therefore I cannot implement IPC in any way in it.
-
Impossible? Get instance of MainWindow from extern WPF-applicationI have two WPF-applications. Let's call them
A
andB
. InA
I wan't to startB
as a new process and get the instance ofB
's MainWindow to further gain access of the controls inB
. WhenA
has started it sets up an instance of theProcess
class to startB
. The instance is kept inA
to help in any other way to access or terminateB
. InA
I have aStartB
method and aGetB
method:public partial class MainWindow : Window
{
Process Process { get; set; }public MainWindow() { InitializeComponent(); } private void Window\_Loaded(object sender, RoutedEventArgs e) { StartB(); GetB(); } void StartB() { var path = @"C:\\Some\\Path\\To\\B.exe"; var info = new ProcessStartInfo(path); Process = new Process(); Process.StartInfo = info; Process.Start(); } void GetB() { var title = Process.MainWindowTitle; var visual = System.Windows.Interop.HwndSource.FromHwnd(Process.MainWindowHandle); var window = visual.RootVisual as Window; }
}
The
StartB
method works. But theGetB
method don't work. This line inGetB
returns null:var visual = System.Windows.Interop.HwndSource.FromHwnd(Process.MainWindowHandle);
I have googled and I found somewhere that the call to
System.Windows.Interop.HwndSource.FromHwnd
should work, but it didn't. Is there a solution for this? Best regards, Stefan -
Better way to access ViewModelsIn my current way to structure a WPF-application I heavily lean on UserControls for my Views and place them in the MainWindow inside a container, usually a DockPanel. For instance in the MainWindow:
For each View I have a corresponding ViewModel. This ViewModel is instantiated inside the View's XAMl-code. In the DataContext element. For instance in the Body View:
I like this approach, because I can alter any properties in the ViewModel and see the View automatically change in the view during design time. But I have not find a good way to access any ViewModels from some class where I happened to need to alter the View through a property in a ViewModel. My current solution - which I don't like - to gain access of the ViewModels is: 1. Give each View a name in the MainWindow.xaml file.
2. Do some logic in the MainWindow to setup the ViewModels for each View.
public partial class MainWindow : Window
{
HeaderViewModel Header { get; set; }
FooterViewModel Footer { get; set; }
BodyViewModel Body { get; set; }public MainWindow() { InitializeComponent(); Header = viewHeader.DataContext as HeaderViewModel; Footer = viewFooter.DataContext as FooterViewModel; Body = viewBody.DataContext as BodyViewModel; }
}
3. Then for every class where I need a ViewModel I need to pass it from the MainWindow in some way.
class SomeClass
{
public void AlterHeaderText(HeaderViewModel header)
{
// Do some logic with viewmodel.
}
}This approach works, but I don't like it. It's annoying to pass ViewModels from the MainWindow every time a class need one or more ViewModels to alter a View. Is there a solution to this approach to improve it? /BR Steffe
-
Call a method inside a Task.Run and return the valueI have a method
Bar
. Bar take some arbitrary amount of time to complete. I want to callBar
from a methodFoo
.Foo
run some code sync and last runBar
async.Bar
returns a value and I wantFoo
to return the same value. Here is the code to reproduce the behavior:Module Module1
Sub Main() Dim i As Integer = Foo() Console.Write("Enter anything: ") Console.ReadLine() Console.WriteLine(i) End Sub Async Function Foo() As Task(Of Integer) Console.WriteLine("Do something sync") Console.WriteLine("Do something sync") Return Await Task.Run(Function() Bar()) End Function Function Bar() As Integer Console.WriteLine("Bar Start") Threading.Thread.Sleep(2000) Console.WriteLine("Bar Stop") Return 5 End Function
End Module
But I get a compile error in the Main method:
Dim i As Integer = Foo()
Value of type Task(Of Integer) cannot be converted to Integer.
I understand the error, but I don't understand how I should solve it. I tried this line:Dim i As Integer = Foo().Result
Which compiles and runs. But the call to the Bar method ran sync, not async. How should I alter the code to run
Bar
async and fromFoo
only return the value fromBar
? -
Cannot add folders (with files) to the .gitignore file in VS Team ExplorerThank you for that tip! I deleted the folders and files. Commited the deleted stuff. Now VS will not try to include the /bin and /obj folders and files in every commit. Thank you!
-
Cannot add folders (with files) to the .gitignore file in VS Team ExplorerUnfortunately I did not. Several commits after the first commit I added the .gitgnore-file. :(( I'm looking for the "Ignore this local item" selection. Please see the answer in this link from StackOverFlow. This option only seem to be available before doing the first commit. I don't understand why. Is there a solution for me?
-
Cannot add folders (with files) to the .gitignore file in VS Team ExplorerI can find the same list of items in my .gitignore. But still the /bin and /obj folders and files are shown in the changes dialog. Here are the items I don't want. Solution folder /.vs folder, sub folders and files. Project A /bin/Debug folder and files. /obj folder, sub folders and files. Project B /bin/Debug folder and files. /obj folder and files. Project C /bin/Debug folder and files.
-
Cannot add folders (with files) to the .gitignore file in VS Team Explorer(Not sure if this is the correct forum. I'll give it a try.) In my Visual Studio solution I have several projects. (ProjectA, ProjectB and so on...) My solution also contains a .gitignore-file. I would like to add all projects´ /bin and /obj folders to the .gitignore file. These folders, and files in them, always updates when I even the smallest changes. So when I want commit something in Team Explorer, I always see this folders and the files. I don't care about them. In other solutions, I have been able to add folders and files to the .gitignore file in the Team Explorer of my choosing. In those cases I have added the /bin and /obj folders. For this particular solution, this is not possible. I wonder what I'm doing wrong. Any suggestions?
-
WinForm - Localize DataGridView with automatical generated columnsHi! I have a DataGridView in a Windows Form application where I want to localize the columns in the DataGridView. I use the DataGridView 's
DataSource
property to populate the DataGridView from a list. Therefore the columns in the DataGridView are genereated automatically after the properies in the list. Here is the code to populate the DataGridView.public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();var p1 = new Person() { Name = "Foo", Age = 1337 }; var p2 = new Person() { Name = "Bar", Age = 42 }; var people = new List() { p1, p2 }; dataGridView1.DataSource = people; }
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}The generated columns in the DataGridView are
Name
andAge
, the same as the properties in thePerson
class. I have set the Form'sLocalizable
property toTrue
. With aLabel
in the Form, I have verified that I can change the Label'sText
property to different values based on theCurrentCulture
/CurrentUICulture
I set. I switch between different cultures in theProgram.cs
file:static class Program
{
/// /// The main entry point for the application.
///
[STAThread]
static void Main()
{
var eng = "en";
var swe = "sv-SE";
var culture = eng;
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(culture);Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
}
My project have generated
Form1.resx
andForm1.sv.resx
files to handle both English and Swedish. In these files I can find the label's text for the English and Swedish languages accordingly. I just don't know how to set the DataGridView's column to different languages. Since the columns are not manually created by me I don't have the appropriate values in the Form1.resx and Form1.sv.resx to set the columns based on the selected language. Is there any solution to this? -
Fail to call Sub from Async methodOf course I have to switch
Function()
toSub()
:doh: Thank you for the correction! -
Fail to call Sub from Async methodI need to call a method (returning void) in an async method. I have problem with the syntax of the Task.Run() in VB. I have a working example in C#. So it's just another: "Parse-this-line-from-C#-into-VB-and-it-should-work". VB-code
Module Module1
Sub Main() Console.WriteLine("Start of Run") Run() Console.WriteLine("End of Run") Console.ReadLine() End Sub Async Sub Run() Dim arg = "LEET 1337" Await Threading.Tasks.Task.Run(Function() Foo(arg)) ' This line fails... End Sub Sub Foo(ByVal asdf As String) Console.WriteLine("Start of Foo") Threading.Thread.Sleep(5000) Console.WriteLine(asdf) Console.WriteLine("End of Foo") End Sub
End Module
C#-code
using System;
using System.Threading;
using System.Threading.Tasks;namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start Run");
Run();
Console.WriteLine("End of Run");
Console.ReadLine();
}static async void Run() { var arg = "LEET 1337"; await Task.Run(() => Foo(arg)); // This line works. } static void Foo(string asdf) { Console.WriteLine("Start Foo"); Thread.Sleep(5000); Console.WriteLine(asdf); Console.WriteLine("End of Foo"); } }
}
-
VB.NET: Failes to assign an Action to a methodThanks! It I tried the
AddressOf
earlier, but beeing used to C# I added parentheses as well:AddressOf(Baz)
. Of course that doesn't work :doh: