Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Mc_Topaz

@Mc_Topaz
About
Posts
204
Topics
84
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Animation on DataGridRow jumps to wrong row when scrolling
    M Mc_Topaz

    Hi! Sorry I don't understand. Can you please explain what you mean?

    WPF help css database wpf tutorial

  • Animation on DataGridRow jumps to wrong row when scrolling
    M Mc_Topaz

    I 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 has HasBirthday = 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>
    
    WPF help css database wpf tutorial

  • Impossible to override a value in an animation located in a style?
    M Mc_Topaz

    I have a style FooStyle with some properties and an animation. I have two other styles Bar1Style and Bar2Style which is based on the FooStyle 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 values FrameOneValue and FrameTwoValue.

    <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>
    
    WPF database wpf question

  • Override a value in base style's resource
    M Mc_Topaz

    Thank 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.

    WPF wpf question learning

  • Override a value in base style's resource
    M Mc_Topaz

    I have two style FooStyle and BarStyle. I also have three TextBlocks and two of them use the styles above. In the FooStyle I have specified a double (the Wid parameter) that is used to set the Width of the TextBlock (txt2) to 20. In the BarStyle I would like to use the FooStyle 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?

    WPF wpf question learning

  • [Updated] Attached Properties to UserControl
    M Mc_Topaz

    I 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"

    WPF wpf

  • Impossible? Get instance of MainWindow from extern WPF-application
    M Mc_Topaz

    :doh: Why didn't I thought of that. I tried it yesterday and it worked great. Thanks!

    WPF csharp wpf com help question

  • Impossible? Get instance of MainWindow from extern WPF-application
    M Mc_Topaz

    It 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

    WPF csharp wpf com help question

  • Impossible? Get instance of MainWindow from extern WPF-application
    M Mc_Topaz

    I 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.

    WPF csharp wpf com help question

  • Impossible? Get instance of MainWindow from extern WPF-application
    M Mc_Topaz

    I have two WPF-applications. Let's call them A and B. In A I wan't to start B as a new process and get the instance of B's MainWindow to further gain access of the controls in B. When A has started it sets up an instance of the Process class to start B. The instance is kept in A to help in any other way to access or terminate B. In A I have a StartB method and a GetB 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 the GetB method don't work. This line in GetB 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

    WPF csharp wpf com help question

  • Better way to access ViewModels
    M Mc_Topaz

    In 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

    WPF wpf csharp design docker question

  • Call a method inside a Task.Run and return the value
    M Mc_Topaz

    I have a method Bar. Bar take some arbitrary amount of time to complete. I want to call Bar from a method Foo. Foo run some code sync and last run Bar async. Bar returns a value and I want Foo 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 from Foo only return the value from Bar?

    Visual Basic help question

  • Cannot add folders (with files) to the .gitignore file in VS Team Explorer
    M Mc_Topaz

    Thank 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!

    - Uncategorised posts - visual-studio csharp collaboration question

  • Cannot add folders (with files) to the .gitignore file in VS Team Explorer
    M Mc_Topaz

    Unfortunately 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?

    - Uncategorised posts - visual-studio csharp collaboration question

  • Cannot add folders (with files) to the .gitignore file in VS Team Explorer
    M Mc_Topaz

    I 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.

    - Uncategorised posts - visual-studio csharp collaboration question

  • Cannot add folders (with files) to the .gitignore file in VS Team Explorer
    M Mc_Topaz

    (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?

    - Uncategorised posts - visual-studio csharp collaboration question

  • WinForm - Localize DataGridView with automatical generated columns
    M Mc_Topaz

    Hi! 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 and Age, the same as the properties in the Person class. I have set the Form's Localizable property to True. With a Label in the Form, I have verified that I can change the Label's Text property to different values based on the CurrentCulture / CurrentUICulture I set. I switch between different cultures in the Program.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 and Form1.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?

    C# tutorial question

  • Fail to call Sub from Async method
    M Mc_Topaz

    Of course I have to switch Function() to Sub() :doh: Thank you for the correction!

    Visual Basic csharp help tutorial

  • Fail to call Sub from Async method
    M Mc_Topaz

    I 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");
        }
    }
    

    }

    Visual Basic csharp help tutorial

  • VB.NET: Failes to assign an Action to a method
    M Mc_Topaz

    Thanks! 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:

    Visual Basic help csharp learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups