Reputation: 1129
I don't exactly know what the problem is since I am almost sure I did what other posts told me to do. I have bound a observablecollection of strings to a comboBox before so it should work.
dataClass:
namespace UIBlocksLib.Data_VM__classes
{
public class BlockController : INotify, IStatementCollection
{
private List<UIStackBlock> _mUIStackBlocks = new List<UIStackBlock>();
public ObservableCollection<string> _mUIVariables = new ObservableCollection<string>() { "VariableA", "VariableB", "VariableC" };
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<string> getVariables
{
get
{
return _mUIVariables;
}
set
{
_mUIVariables = value;
onPropertyChanged("_mUIVariables");
}
}
public BlockController()
{
}
public void addVariable(string aVariableName)
{
_mUIVariables.Add(aVariableName);
onPropertyChanged("_mUIVariables");
}
public void addUIStackBlock(UIStackBlock aUIStackBlock)
{
throw new NotImplementedException();
}
public void onPropertyChanged(string aPropertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(aPropertyName));
}
public void removeStackBlockByIndex(int aIndex)
{
throw new NotImplementedException();
}
}
}
my objectDataProvider in my generic.xaml
<ObjectDataProvider x:Key="dataObject"
ObjectType="{x:Type dataClass:BlockController}"
MethodName="getVariables">
</ObjectDataProvider>
and my style which is bound to my class
<Style TargetType="{x:Type local:UISet}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:UISet}">
<Grid>
<Rectangle MouseLeftButtonDown="MouseLeftButtonDown" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Fill="#AD2B27" ClipToBounds="True"/>
<ComboBox DataContext="{staticResource dataObject}" Background="#FFEE4A4A" x:Name="comboBox" MinHeight="30" MinWidth="70" Margin="5, 23" ItemsSource="{Binding}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
also tried making the context static/ not using a context/ using the name of the variable. the compiler does recognize the getVariables when looking through the suggestions.
Upvotes: 2
Views: 478
Reputation: 7325
In your Code getVariables is not a method but a property. This way it should work:
<ObjectDataProvider x:Key="dataObject"
ObjectType="{x:Type dataClass:BlockController}"
MethodName="GetVariables">
</ObjectDataProvider>
public ObservableCollection<string> GetVariables()
{
return getVariables;
}
Upvotes: 2