Related
So Starting off small i want to find an IP address if an account has been logged out on my servers, I've made the GUI, its fine but the button doesn't work, any idea where I've gone wrong?
in theory it should return a string which contains an IP address, a time stamp and a date but i'm new to power shell so i'm not really 100% sure what i'm doing, any help would be appreciated
inputXML = #"
<Window x:Class="UnlockerGui.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="538.433">
<Grid HorizontalAlignment="Left" Width="538" Margin="0,0,-8,-21" RenderTransformOrigin="0.295,0.552">
<Grid.RowDefinitions>
<RowDefinition Height="101*"/>
<RowDefinition Height="239*"/>
</Grid.RowDefinitions>
<TextBox x:Name="TxtName" HorizontalAlignment="Left" Height="45" Margin="10,10,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="177"/>
<Button Grid.Row="0" x:Name="BtnSearch" Content="Search" HorizontalAlignment="Left" Margin="192,10,0,0" VerticalAlignment="Top" Width="271" Height="45"/>
<ListBox x:Name="LbResults" HorizontalAlignment="Left" Height="246" Margin="10,60,0,0" Grid.Row="0"
Grid.RowSpan="2" VerticalAlignment="Top" Width="504"/>
</Grid>
</Window>
"#
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
#===========================================================================
# Load XAML Objects In PowerShell
#===========================================================================
$xaml.SelectNodes("//*[#Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
Function Get-FormVariables{
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}
Get-FormVariables
#===========================================================================
# Actually make the objects work
#===========================================================================
#Sample entry of how to add data to a field
#$vmpicklistView.items.Add([pscustomobject]#{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
Function Get-Data{
param([string]$Localusername)
string[] $results1 =
Get-WinEvent -ComputerName SERVERNAME1 -FilterHashtable #{logname='security';id=4771;data=$Localusername} |
Select-Object -Property timecreated,
#{Name='computername';expression={$_.properties[6].value.Split(':')[3]}}
foreach($string in $results1)
{
$WPFLbResults.Items.Add($results1[$string])
}
string[] $results2 =
Get-WinEvent -ComputerName SERVERNAME2 -FilterHashtable #{logname='security';id=4771;data=$Localusername} |
Select-Object -Property timecreated,
#{Name='computername';expression={$_.properties[6].value.Split(':')[3]}}
foreach($string in $results2)
{
$WPFLbResults.Items.Add($results2[$string])
}
string[] $results3 =
Get-WinEvent -ComputerName SERVERNAME3 -FilterHashtable #{logname='security';id=4771;data=$Localusername} |
Select-Object -Property timecreated,
#{Name='computername';expression={$_.properties[6].value.Split(':')[3]}}
foreach($string in $results3)
{
$WPFLbResults.Items.Add($results3[$string])
}
}
#===========================================================================
# Shows the form
#===========================================================================
$Form.ShowDialog() | Out-Null
$WPFBtnSearch.Add_Click({
$username = $WPFTxtName.Text
Get-Data($username)
})
I'm trying to create a form with XAML. The problem i'm facing is that i cant retrieve the value's from a datagrid. What i want is to loop true al the checked checkboxes.
The code is use is:
XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window_GuiManagement" Title="Remove Company User" WindowStartupLocation = "CenterScreen"
Width = "587.307" Height = "540.023" Visibility="Visible" WindowStyle="ToolWindow" ResizeMode="NoResize" Topmost="True">
<Grid>
<Label x:Name="lblCompany" Content="Company:" HorizontalAlignment="Left" Margin="11,10,0,0" Height="26" VerticalAlignment="Top"/>
<ComboBox x:Name="cbCompanys" Margin="10,36,10,0" VerticalAlignment="Top"/>
<Label x:Name="lbluser" Content="User:" HorizontalAlignment="Left" Margin="11,63,0,0" VerticalAlignment="Top"/>
<CheckBox x:Name="chkbMultiSelect" Content="MultiSelect" Margin="481,69,10,0" VerticalAlignment="Top" Width="90"/>
<DataGrid x:Name="dgUsers" Margin="11,94,10,0" VerticalAlignment="Top" Height="299" SelectionMode="Single" AlternationCount="1">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{x:Null}" ClipboardContentBinding="{x:Null}" CanUserSort="False" CanUserResize="False" IsReadOnly="False"/>
</DataGrid.Columns>
</DataGrid>
<CheckBox x:Name="chkbBackupFiles" Content="Backup Files" HorizontalAlignment="Left" Margin="11,398,0,0" VerticalAlignment="Top" IsChecked="True"/>
<CheckBox x:Name="chkbmail" Content="Backup Mail" HorizontalAlignment="Left" Margin="11,418,0,0" VerticalAlignment="Top" IsChecked="True"/>
<CheckBox x:Name="chkblocation" Content="Open backup location" HorizontalAlignment="Left" Margin="11,438,0,0" VerticalAlignment="Top" IsChecked="True"/>
<Button x:Name="btnSend" Content="Send" Margin="491,469,10,0" VerticalAlignment="Top"/>
<CheckBox x:Name="chkblocation_Copy" Content="Open backup location" HorizontalAlignment="Left" Margin="11,438,0,0" VerticalAlignment="Top" IsChecked="True"/>
</Grid>
</Window>
Powershell:
function Remove-GuiCompanyUser {
begin {
#Xaml Path
[xml]$xaml = Get-Content "$Global:relPathXaml\RemoveCompanyUser.xaml"
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
# Try to read the XAML to form
try {
$Form=[Windows.Markup.XamlReader]::Load( $reader )
} catch {
Write-Host "Something went wrong..."
}
#Setting al the fields to varialbe
$cbCompanys = $Form.FindName("cbCompanys")
$chkbMultiSelect = $Form.FindName("chkbMultiSelect")
$dgUsers = $Form.FindName("dgUsers")
$chkbBackupFiles = $Form.FindName("chkbBackupFiles")
$chkbBackupMail = $Form.FindName("chkbBackupMail")
$chkblocation = $Form.FindName("chkblocation")
$btnSend = $Form.FindName("btnSend")
}
process {
# Form setup
$Form.Background = $Global:BackColor
# for now disable the multiselect button
$chkbMultiSelect.IsEnabled = $false
# Add scripts to Company Combobox
foreach ($Company in ($Global:Companys | sort Name)) {
[void] $cbCompanys.Items.Add($Company.Name)
}
# Add on checked to CheckBox Multiselect
$chkbMultiSelect.Add_Checked({
$dgUsers.SelectionMode = "Extended"
})
# Add on UnChecked to CheckBox Multiselect
$chkbMultiSelect.Add_UnChecked({
$dgUsers.SelectionMode = "Single"
})
# Add onchange to Company Combobox
$cbCompanys_Add_SelectionChanged = {
# Disable User Combobox
$cbCompanys.IsEnabled = $False
# Clear the Users Combobox
$dgUsers.Clear()
# Get all users of company
$CompUsers = Get-CompanyUser -Company $cbCompanys.SelectedItem | select DisplayName, UserPrincipalName, SamAccountName | sort DisplayName
# Add users to DataGrid
$dgUsers.ItemsSource = $CompUsers
# Allow sorting on all columns
$dgUsers.Columns | ForEach-Object {
$_.CanUserSort = $True
$_.IsReadOnly = $True
}
# Set Columns ReadOnly of not
$dgUsers.Columns[0].IsReadOnly = $False
# Enable User Combobox
$cbCompanys.IsEnabled = $True
}
# Add selectionchanged function to Combobox
$cbCompanys.Add_SelectionChanged($cbCompanys_Add_SelectionChanged)
# Set action to button
$btnSend.Add_Click({
# Get selected items
$SelCompany = $cbCompanys.SelectedItem
# Checking if all fiels contain value
if (!($SelCompany)) {
EmptyFormField -Field "Company"
} else {
for($i=0;$i -lt $dgUsers.items.count;$i++){
if($dgUsers.Rows[$i].Cells[0].Value -eq $true)
{
write-host "cell #$i is checked"
}
}
}
})
# Start form
$Form.ShowDialog() | out-null
}
end {
}
}
After some googleing i found out you can call the rows by $dgUsers.Rows but that value doesn't exist. $dgUsers.Columns does exist.. I can call al my value's with $dgUsers.Items. But that only gives the array back I put in to it. So i don't have the checkboxes..
Anyone an idea?
My powershell version is:
Major Minor Build Revision
----- ----- ----- --------
4 0 30319 34209
Greetings,
Jos Vink
I am attempting to split an XML string like this,
"<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="12" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0"><Paragraph Margin="0,0,0,0"><Span><Run>This is to test a split page function</Run></Span></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph Margin="0,0,0,0"><Span><Run>PAGE_BREAK</Run></Span></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph Margin="0,0,0,0"><Span><Run>This is page two</Run></Span></Paragraph><Paragraph Margin="0,0,0,0"></Paragraph><Paragraph><Run></Run></Paragraph></Section>"
using "PAGE_BREAK" in the string - and would have expected it to split into two arrays, but instead it's splitting it into 18. Any idea what I'm doing wrong here?
Dim IsPageBreak As Boolean = False
Dim vPages() As String = Nothing
Dim vPageNumbers As Integer = 0
If Letter_String.Contains("PAGE_BREAK") Then
vPages = Letter_String.Split("PAGE_BREAK")
vPageNumbers = vPages.Length
IsPageBreak = True
End If
Don't know why you would want to do that, but this is gives the results you want.
Dim xe As XElement
xe = <Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="12" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0">
<Paragraph Margin="0,0,0,0">
<Span>
<Run>This is to test a split page function</Run>
</Span>
</Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph Margin="0,0,0,0">
<Span>
<Run>PAGE_BREAK</Run>
</Span>
</Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph Margin="0,0,0,0">
<Span>
<Run>This is page two</Run>
</Span>
</Paragraph>
<Paragraph Margin="0,0,0,0"></Paragraph>
<Paragraph><Run></Run></Paragraph>
</Section>
Dim vPages() As String = Strings.Split(xe.ToString, "PAGE_BREAK")
I have a resource:
<Application.Resources>
<PathIcon x:Key="appbar_share" Data="M10,16.6...http://modernuiicons.com/... />
</Application.Resources>
This resource renders fine when referenced through XAML:
<Page.BottomAppBar>
<CommandBar>
<AppBarButton Icon="{StaticResource appbar_share}" />
</CommandBar>
</Page.BottomAppBar>
But is not usable from code behind:
Dim Button1 As New AppBarButton
Dim MyPathIcon As PathIcon = _
TryCast(Application.Current.Resources("appbar_share"), PathIcon)
Button1.Icon = MyPathIcon
This is the error i get:
Similar exception can happen if your path data is not correct. Why does your PathIcon Data contain a link to modernuiicons.com? It shouldn't be there, it should have just the path data inside. For example:
<Application.Resources>
<PathIcon x:Key="appbar_share" Data="M41.1684,45.487038C44.33276,45.476124 47.116478,47.775484 47.619183,50.997017 48.173893,54.552612 45.741444,57.884518 42.186676,58.439186 38.631909,58.993855 35.299843,56.561596 34.745133,53.007202 34.189225,49.452806 36.621571,46.1208 40.176239,45.566132 40.509629,45.514019 40.841049,45.488167 41.1684,45.487038z M10.237135,35.558062L10.350618,35.901613C13.537862,45.15811,22.303875,51.450747,32.124443,51.476969L32.24012,51.475981 32.232979,51.574453C32.204815,52.168505 32.235886,52.774008 32.33125,53.384045 32.497891,54.451855 32.847706,55.446404 33.343685,56.340675L33.528836,56.655979 33.263104,56.66925C20.287924,57.165882,8.592234,48.699957,4.9941953,36.24795L4.991,36.236345 5.2068322,36.273844C6.0781415,36.403109 6.9829696,36.404837 7.8980048,36.262007 8.6605371,36.142996 9.3857501,35.930498 10.063782,35.638014z M6.5030173,20.89604C9.6663612,20.885077 12.450289,23.184638 12.954178,26.407125 13.508891,29.961675 11.076529,33.293532 7.521735,33.848207 3.9656423,34.402784 0.63486499,31.970687 0.078820122,28.416241 -0.47588428,24.861691 1.9564295,21.529734 5.5112136,20.975158 5.8444722,20.923035 6.1757749,20.897175 6.5030173,20.89604z M58.8219,18.574822L59.004681,19.084795C59.543209,20.648768 59.951763,22.281796 60.215809,23.973269 61.800083,34.122046 57.788403,43.852476 50.472401,50.025568L49.996003,50.417795 49.950493,50.167978C49.607575,48.524141,48.825226,47.070471,47.747254,45.912016L47.524395,45.683733 47.536305,45.673433C53.238133,40.622065 56.328049,32.862471 55.065937,24.777964 54.881249,23.594744 54.609913,22.446564 54.259404,21.338879L54.134854,20.961815 54.432953,20.907509C56.076813,20.564614,57.530503,19.782418,58.688969,18.704576z M52.585079,5.624033C55.74844,5.6138992 58.532292,7.9135618 59.036179,11.13474 59.590893,14.689362 57.158524,18.021196 53.603829,18.575868 50.047627,19.131741 46.715535,16.699662 46.16082,13.145139 45.606106,9.5893164 48.038472,6.2575331 51.59327,5.7028704 51.926533,5.6508484 52.25784,5.6250811 52.585079,5.624033z M32.156784,0.00014686584C37.614365,-0.017484665,42.811852,1.5448036,47.233734,4.3107109L47.724335,4.6257896 47.518517,4.7606697C46.206982,5.6667137,45.162045,6.9076052,44.488583,8.3395329L44.348809,8.6562643 43.997319,8.4421854C39.538208,5.7988148 34.168194,4.6310177 28.646389,5.4929276 20.363682,6.7857971 13.798057,12.32467 10.820051,19.546529L10.815107,19.558941 10.701824,19.495367C9.3059848,18.755269,7.7060798,18.377093,6.0457643,18.465707L5.6350406,18.498096 5.7456864,18.199476C9.2659248,9.0405502 17.451128,1.9652042 27.841681,0.34318161 29.291645,0.11686516 30.733063,0.0047473907 32.156784,0.00014686584z" />
</Application.Resources>
(Share icon path example taken from Metro Studio)
I'm having problems binding an variable color, which i have defined in a class, such that it can fill an area for me.
<UserControl x:Name="Portugal" x:Class="MiddleAgeWar1.UserControl_Portugal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:country="clr-namespace:MiddleAgeWar1.ViewModel"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="152" d:DesignWidth="88">
<Grid x:Name="LayoutRoot">
<Path x:Name="Path" Stretch="Fill" Fill="{Binding color}" StrokeThickness="1.34983" StrokeLineJoin="Round" Stroke="#D5000000" Data="F1 M 43.4622,0.674866C 43.4622,0.674866 42.2811,4.3869 42.1967,4.97748C 42.1124,5.56805 41.8593,5.56805 41.5218,6.07428C 41.1844,6.58038 41.5218,6.74921 41.0156,8.43646C 40.5094,10.1236 41.0156,9.44879 41.0156,10.883C 41.0156,12.3171 40.9313,12.1485 40.9313,12.1485L 42.028,14.7639C 42.028,14.7639 42.7873,17.7165 42.5342,19.1507C 42.2811,20.5849 41.8593,21.5974 41.2687,22.1035C 40.6782,22.6097 40.2563,23.7065 39.6658,24.0439C 39.0752,24.3813 38.7378,25.0562 37.3036,26.0687C 35.8694,27.081 36.713,27.8403 36.2912,28.8526C 35.8694,29.8649 36.1225,30.2868 35.8694,30.9617C 35.6163,31.6367 35.8694,34.252 35.8694,34.5894C 35.8694,34.9269 34.7727,38.0484 34.7727,38.0484C 34.7727,38.0484 34.5196,38.3858 33.001,40.6636C 31.4824,42.9415 32.3261,41.0855 31.145,41.9291C 29.9639,42.7728 29.7952,42.6041 28.6141,43.3633C 27.433,44.1226 28.1922,44.9662 28.0235,46.5692C 27.8548,48.1721 27.686,48.1721 27.686,49.0158C 27.686,49.8594 27.686,50.9561 27.686,52.3903C 27.686,53.8244 27.2642,54.3307 26.758,55.2587C 26.2519,56.1867 26.3362,55.9337 25.83,56.3555C 25.3238,56.7773 25.3238,56.6929 24.3115,57.1992C 23.2991,57.7053 23.6365,57.2835 23.2147,57.5366C 22.7929,57.7896 22.6242,58.2115 20.0089,61.3329C 17.3936,64.4544 19.1652,62.5141 18.659,63.4421C 18.1529,64.3701 18.406,64.0327 17.8998,65.045C 17.3936,66.0573 17.3936,66.1418 16.9718,66.9011C 16.5499,67.6602 16.5499,67.3228 15.5376,68.0821C 14.5252,68.8414 15.3688,68.6727 15.0314,69.1789C 14.6939,69.685 14.3565,69.6006 12.4161,71.0349C 10.4757,72.4691 11.8255,71.8785 11.0662,72.3847C 10.307,72.8908 10.307,72.8909 8.53531,73.5659C 6.76366,74.2407 6.84802,75.8437 6.84802,75.8437L 3.97963,78.2059C 2.79853,79.1339 3.64217,79.0495 3.30471,79.8931C 2.96726,80.7368 2.46107,82.7615 1.61742,83.6052C 0.773778,84.4488 1.53306,84.955 1.27997,85.5456C 1.02687,86.1362 0.183228,90.1013 1.02687,90.4387C 1.87052,90.7761 2.88289,90.6075 6.08874,90.3543C 9.29459,90.1013 6.84802,90.3543 9.04149,89.9326C 11.235,89.5107 10.5601,89.5107 11.6568,89.1733C 12.7535,88.8358 12.0786,89.1733 12.4161,89.342C 12.7535,89.5107 14.4408,91.7885 14.4408,92.5478C 14.4408,93.3071 14.4408,93.3914 14.1877,94.0663C 13.9346,94.7413 13.9346,94.7413 13.4284,95.1631C 12.9223,95.5849 12.2473,95.7537 11.4881,95.9224C 10.7288,96.091 9.9695,96.4285 8.61967,96.8504C 7.26985,97.2722 8.02912,97.1035 7.35421,97.3566C 6.67929,97.6097 7.10111,97.5253 4.73891,98.7908C 2.37671,100.056 4.73891,99.2126 4.73891,100.056C 4.73891,100.9 5.49819,100.9 6.00438,101.237C 6.51056,101.575 8.53531,101.912 10.3913,102.165C 12.2473,102.418 14.5252,102.587 14.5252,102.587L 15.875,103.768L 15.4532,106.89C 15.4532,108.493 15.4532,109.252 15.2845,111.445C 15.1157,113.639 14.947,112.373 14.4408,113.301C 13.9346,114.229 13.9346,114.483 13.091,116.254C 12.2473,118.026 12.7535,117.182 11.1506,119.46C 9.54769,121.738 10.307,121.569 10.0539,123.594C 9.80078,125.619 9.54768,124.353 8.19785,126.04C 6.84802,127.728 7.10111,127.559 6.34183,129.162C 5.58255,130.765 5.75128,129.921 4.48582,132.115C 3.22035,134.308 4.06399,133.043 3.64217,133.971C 3.22035,134.899 3.30471,135.996 3.22035,138.02L 3.97963,141.142C 4.82327,142.238 6.08874,143.166 8.70404,143.673C 11.3193,144.179 10.2226,144.601 11.6568,144.938C 13.091,145.276 13.5128,146.035 15.0314,146.71C 16.5499,147.385 16.2125,147.553 17.1405,147.722C 18.0685,147.891 18.9121,148.397 19.5871,148.482C 20.262,148.566 21.6962,148.903 22.5398,148.903C 23.3835,148.903 24.3115,148.819 24.3115,148.819L 28.9515,148.144L 31.2997,148.263C 31.2997,148.263 32.7128,148.179 33.2822,148.158C 33.8517,148.137 34.6532,148.137 36.0873,148.032C 37.5215,147.926 37.8801,147.926 38.6816,148.032C 39.483,148.137 41.8452,148.411 41.8452,148.411L 45.1354,148.924L 49.6958,151.635C 49.6958,151.635 49.4708,140.162 50.8207,130.713C 52.1705,121.264 46.9962,119.464 59.8196,106.866C 72.643,94.2674 73.7678,89.768 74.8927,87.0684C 76.0175,84.3687 75.7926,67.4958 76.0175,60.7466C 76.2425,53.9975 81.9441,38.369 83.2096,36.2598C 84.4751,34.1507 86.5842,28.0765 87.6809,19.1341C 88.7777,10.1916 66.5898,3.52667 65.24,2.7674C 63.8901,2.008 51.2355,3.18915 50.4762,2.34552C 49.7169,1.50189 43.5021,0.770813 43.4622,0.674866 Z " Margin="0,-0.001,-0.409,-0.309" UseLayoutRounding="False" />
<Grid HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="88"/>
</Grid>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
namespace MiddleAgeWar1.ViewModel
{
class Country
{
public SolidColorBrush color = new SolidColorBrush(Colors.Green);
}
}
I wish to bind the SolidColorBrush color such that it fills my area.
I think you should rearrange your code and start using MVVM.
You can easily get it to work through MVVM.
Go to Nuget and search for MVVM or Galsoft.
In Model you define what you want.
Then you can create your country as a View.
And then binding is easily done in ViewModel.
It will take some time to get into it. But when you do everything is easy from there!!
bind it to your grid like this..
<Grid HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="88" Background="{Binding color}"/>
and also implement InotifyPropetyChanged on your class ..it is good to do that...you can do that like this..
in your class do this..
class Country:INotifyPropertyChanged
{
public Country()
{
this.InitializeComponent();
this.DataContext = this;
}
private SolidColorBrush _color;
public SolidColorBrush color
{
get
{
return _color;
}
set
{
_color = value;
FirePropertyChanged("color");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void FirePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}