Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7492131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:22:22+00:00 2026-05-29T16:22:22+00:00

I attached my XAML and .CS sample code so you can see what is

  • 0

I attached my XAML and .CS sample code so you can see what is it all about. I have MainWindow with at least 10 buttons (one part for media element, second for playlist, and third for application itself. Also, there are helper methods I use in all these mentioned methods.

It gets really ugly having only one .cs file with dozens of methods. I have no idea how to separate these and still keep communication between controls and methods.

I have Main Window like this in XAML

<Window x:Class="Modulated.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="194" Width="525">
<Grid>
    <Button Content="Sort Asc" Height="23" HorizontalAlignment="Left" Margin="10,12,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="sort_asc" />
    <Button Content="Sort Desc" Height="23" HorizontalAlignment="Left" Margin="12,42,0,0" Name="button4" VerticalAlignment="Top" Width="75" />
    <ListBox Height="131" HorizontalAlignment="Left" Margin="99,12,0,0" Name="listBox1" VerticalAlignment="Top" Width="70" >
        <ListBoxItem>1</ListBoxItem>
        <ListBoxItem>2</ListBoxItem>
        <ListBoxItem>3</ListBoxItem>
    </ListBox>
    <MediaElement Height="131" HorizontalAlignment="Left" Margin="187,12,0,0" Name="mediaElement1" VerticalAlignment="Top" Width="165" />
    <Button Content="Play" Height="23" HorizontalAlignment="Left" Margin="372,12,0,0" Name="btnPlay" VerticalAlignment="Top" Width="75" Click="play" />
    <Button Content="Stop" Height="23" HorizontalAlignment="Left" Margin="372,42,0,0" Name="btnStop" VerticalAlignment="Top" Width="75" Click="stop" />
    <Button Content="Next" Height="23" HorizontalAlignment="Left" Margin="372,71,0,0" Name="btnNext" VerticalAlignment="Top" Width="75" Click="next" />
</Grid>

and MainWindow.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace Modulated
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void play(object sender, RoutedEventArgs e)
    {
        mediaElement1.Play();
    }

    private void stop(object sender, RoutedEventArgs e)
    {
        mediaElement1.Stop();
    }

    private void next(object sender, RoutedEventArgs e)
    {}

    private void sort_asc(object sender, RoutedEventArgs e)
    {}
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:22:24+00:00Added an answer on May 29, 2026 at 4:22 pm

    A good way to separate logic and presentation is the MVVM design pattern. You can find a tutorial on it here:
    http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone provide the XAML for creating customized check boxes. I have attached the
In Xaml I can set a custom attached property using local:TestClass.TestProperty=1 An I can
In one of the apps of mine I have a performance problem I can’t
I am puzzled by this: I have made a very simple example: MainWindow.xaml: <Window
I can't get the following XAML to work as I want. All bindings work
I have the following simple code (see below) I copied from a book. But
I have View(XAML included) attached to my ViewModel with commands. I need to invoke
In my code attached below, I'm trying to upload a file via ASP.NET. I
I was trying out attached properties and style triggers hoping to learn more about
For the attached code, I get the following compile time error : exception during

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.